<!DOCTYPE HTML>
<html lang="zh-CN">


<head>
    <meta charset="utf-8">
    <meta name="keywords" content="斐讯N1折腾教程, 搞机の基地">
    <meta name="description" content="主要是已折腾N1为主，测试各种固件以及盒子玩法。">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <meta name="referrer" content="no-referrer-when-downgrade">
    <!-- Global site tag (gtag.js) - Google Analytics -->


    <title>斐讯N1折腾教程 | 搞机の基地</title>
    <link rel="icon" type="image/png" href="/favicon.png">
    


    <!-- bg-cover style     -->



<link rel="stylesheet" type="text/css" href="/libs/awesome/css/all.min.css">
<link rel="stylesheet" type="text/css" href="/libs/materialize/materialize.min.css">
<link rel="stylesheet" type="text/css" href="/libs/aos/aos.css">
<link rel="stylesheet" type="text/css" href="/libs/animate/animate.min.css">
<link rel="stylesheet" type="text/css" href="/libs/lightGallery/css/lightgallery.min.css">
<link rel="stylesheet" type="text/css" href="/css/matery.css">
<link rel="stylesheet" type="text/css" href="/css/my.css">
<link rel="stylesheet" type="text/css" href="/css/dark.css" media="none" onload="if(media!='all')media='all'">




    <link rel="stylesheet" href="/libs/tocbot/tocbot.css">
    <link rel="stylesheet" href="/css/post.css">




    
        <link rel="stylesheet" type="text/css" href="/css/reward.css">
    



    <script src="/libs/jquery/jquery-3.6.0.min.js"></script>

<meta name="generator" content="Hexo 6.3.0"></head>


<body>
    <header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="nav-wrapper container">
            <div class="brand-logo">
                <a href="/" class="waves-effect waves-light">
                    
                    <img src="/medias/logo.png" class="logo-img" alt="LOGO">
                    
                    <span class="logo-span">搞机の基地</span>
                </a>
            </div>
            

<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fas fa-bars"></i></a>
<ul class="right nav-menu">
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/" class="waves-effect waves-light">
      
      <i class="fas fa-home" style="zoom: 0.6;"></i>
      
      <span>首页</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="" class="waves-effect waves-light">

      
      <i class="fas fa-project-diagram"" style="zoom: 0.6;"></i>
      
      <span>项目</span>
      <i class="fas fa-chevron-down" aria-hidden="true" style="zoom: 0.6;"></i>
    </a>
    <ul class="sub-nav menus_item_child ">
      
      <li>
        <a target="_blank" rel="noopener" href="https://github.com/liangyoufeng/devpos">
          
          <span>devops</span>
        </a>
      </li>
      
    </ul>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/tags" class="waves-effect waves-light">
      
      <i class="fas fa-tags" style="zoom: 0.6;"></i>
      
      <span>标签</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/categories" class="waves-effect waves-light">
      
      <i class="fas fa-bookmark" style="zoom: 0.6;"></i>
      
      <span>分类</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/archives" class="waves-effect waves-light">
      
      <i class="fas fa-archive" style="zoom: 0.6;"></i>
      
      <span>归档</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/about" class="waves-effect waves-light">
      
      <i class="fas fa-user-circle" style="zoom: 0.6;"></i>
      
      <span>关于</span>
    </a>
    
  </li>
  
  <li>
    <a href="#searchModal" class="modal-trigger waves-effect waves-light">
      <i id="searchIcon" class="fas fa-search" title="搜索" style="zoom: 0.85;"></i>
    </a>
  </li>
  <li>
    <a href="javascript:;" class="waves-effect waves-light" onclick="switchNightMode()" title="深色/浅色模式" >
      <i id="sum-moon-icon" class="fas fa-sun" style="zoom: 0.85;"></i>
    </a>
  </li>
</ul>


<div id="mobile-nav" class="side-nav sidenav">

    <div class="mobile-head bg-color">
        
        <img src="/medias/logo.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">搞机の基地</div>
        <div class="logo-desc">
            
            用来测试知识库
            
        </div>
    </div>

    <ul class="menu-list mobile-menu-list">
        
        <li class="m-nav-item">
	  
		<a href="/" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-home"></i>
			
			首页
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="javascript:;">
			
				<i class="fa-fw fas fa-project-diagram""></i>
			
			项目
			<span class="m-icon"><i class="fas fa-chevron-right"></i></span>
		</a>
            <ul  style="background:  ;" >
              
                <li>

                  <a target="_blank" rel="noopener" href="https://github.com/liangyoufeng/devpos " style="margin-left:75px">
				  
		          <span>devops</span>
                  </a>
                </li>
              
            </ul>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/tags" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-tags"></i>
			
			标签
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/categories" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-bookmark"></i>
			
			分类
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/archives" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-archive"></i>
			
			归档
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/about" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-user-circle"></i>
			
			关于
		</a>
          
        </li>
        
        
        <li><div class="divider"></div></li>
        <li>
            <a href="https://github.com/blinkfox/hexo-theme-matery" class="waves-effect waves-light" target="_blank">
                <i class="fab fa-github-square fa-fw"></i>Fork Me
            </a>
        </li>
        
    </ul>
</div>


        </div>

        
            <style>
    .nav-transparent .github-corner {
        display: none !important;
    }

    .github-corner {
        position: absolute;
        z-index: 10;
        top: 0;
        right: 0;
        border: 0;
        transform: scale(1.1);
    }

    .github-corner svg {
        color: #0f9d58;
        fill: #fff;
        height: 64px;
        width: 64px;
    }

    .github-corner:hover .octo-arm {
        animation: a 0.56s ease-in-out;
    }

    .github-corner .octo-arm {
        animation: none;
    }

    @keyframes a {
        0%,
        to {
            transform: rotate(0);
        }
        20%,
        60% {
            transform: rotate(-25deg);
        }
        40%,
        80% {
            transform: rotate(10deg);
        }
    }
</style>

<a href="https://github.com/blinkfox/hexo-theme-matery" class="github-corner tooltipped hide-on-med-and-down" target="_blank"
   data-tooltip="Fork Me" data-position="left" data-delay="50">
    <svg viewBox="0 0 250 250" aria-hidden="true">
        <path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
        <path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2"
              fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path>
        <path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z"
              fill="currentColor" class="octo-body"></path>
    </svg>
</a>
        
    </nav>

</header>

    



<div class="bg-cover pd-header post-cover" style="background-image: url('/images/%E6%96%90%E8%AE%AFN1%E6%8A%98%E8%85%BE%E6%95%99%E7%A8%8B/top.jpg')">
    <div class="container" style="right: 0px;left: 0px;">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <h1 class="description center-align post-title">斐讯N1折腾教程</h1>
                </div>
            </div>
        </div>
    </div>
</div>




<main class="post-container content">

    
    <div class="row">
    <div id="main-content" class="col s12 m12 l9">
        <!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            <div class="row tag-cate">
                <div class="col s7">
                    
                    <div class="article-tag">
                        
                            <a href="/tags/%E8%BD%AF%E8%B7%AF%E7%94%B1/">
                                <span class="chip bg-color">软路由</span>
                            </a>
                        
                            <a href="/tags/openwrt/">
                                <span class="chip bg-color">openwrt</span>
                            </a>
                        
                            <a href="/tags/armbian/">
                                <span class="chip bg-color">armbian</span>
                            </a>
                        
                            <a href="/tags/%E7%94%B5%E8%A7%86%E7%9B%92%E5%AD%90/">
                                <span class="chip bg-color">电视盒子</span>
                            </a>
                        
                    </div>
                    
                </div>
                <div class="col s5 right-align">
                    
                    <div class="post-cate">
                        <i class="fas fa-bookmark fa-fw icon-category"></i>
                        
                            <a href="/categories/%E8%BD%AF%E8%B7%AF%E7%94%B1%E6%8A%98%E8%85%BE%E5%90%88%E9%9B%86/" class="post-category">
                                软路由折腾合集
                            </a>
                        
                    </div>
                    
                </div>
            </div>

            <div class="post-info">
                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-minus fa-fw"></i>发布日期:&nbsp;&nbsp;
                    2023-06-26
                </div>
                

                

                

                

                
            </div>
        </div>
        <hr class="clearfix">

        
        <!-- 是否加载使用自带的 prismjs. -->
        <link rel="stylesheet" href="/libs/prism/prism.min.css">
        

        

        <div class="card-content article-card-content">
            <div id="articleContent">
                <h1 id="N1优化步骤"><a href="#N1优化步骤" class="headerlink" title="N1优化步骤"></a>N1优化步骤</h1><h2 id="IP设置"><a href="#IP设置" class="headerlink" title="IP设置"></a>IP设置</h2><p>1、先使用命令ip a 查看网卡mac信息和网卡名，一般默认是eth0</p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">root@armbian:~<span class="token comment"># ip a</span>
<span class="token number">1</span>: lo: <span class="token operator">&lt;</span>LOOPBACK,UP,LOWER_UP<span class="token operator">></span> mtu <span class="token number">65536</span> qdisc noqueue state UNKNOWN group default qlen <span class="token number">1000</span>
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet <span class="token number">127.0</span>.0.1/8 scope <span class="token function">host</span> lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope <span class="token function">host</span>
       valid_lft forever preferred_lft forever
<span class="token number">2</span>: sit0@NONE: <span class="token operator">&lt;</span>NOARP<span class="token operator">></span> mtu <span class="token number">1480</span> qdisc noop state DOWN group default qlen <span class="token number">1000</span>
    link/sit <span class="token number">0.0</span>.0.0 brd <span class="token number">0.0</span>.0.0
<span class="token number">3</span>: ip6tnl0@NONE: <span class="token operator">&lt;</span>NOARP<span class="token operator">></span> mtu <span class="token number">1452</span> qdisc noop state DOWN group default qlen <span class="token number">1000</span>
    link/tunnel6 :: brd :: permaddr ba38:f08:8488::
<span class="token number">4</span>: eth0: <span class="token operator">&lt;</span>BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP<span class="token operator">></span> mtu <span class="token number">1500</span> qdisc mq state UP group default qlen <span class="token number">1000</span>
    link/ether fc:7c:02:4a:bf:21 brd ff:ff:ff:ff:ff:ff
    inet <span class="token number">192.168</span>.188.10/24 brd <span class="token number">192.168</span>.188.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::fe7c:2ff:fe4a:bf21/64 scope <span class="token function">link</span> noprefixroute
       valid_lft forever preferred_lft forever
<span class="token number">5</span>: wlan0: <span class="token operator">&lt;</span>NO-CARRIER,BROADCAST,MULTICAST,UP<span class="token operator">></span> mtu <span class="token number">1500</span> qdisc fq state DOWN group default qlen <span class="token number">1000</span>
    link/ether 9e:61:2a:a6:e1:02 brd ff:ff:ff:ff:ff:ff<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<p>2、创建cat &gt; &#x2F;etc&#x2F;network&#x2F;interfaces.d&#x2F;ifcfg-eth0 文件，内容如下：</p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">cat</span> <span class="token operator">></span> /etc/network/interfaces.d/ifcfg-eth0 <span class="token operator">&lt;&lt;</span> <span class="token string">EOF
#网卡名跟上面信息一样
auto eth0
# 设置静态IP地址
iface eth0 inet static
        # 自动开启网卡混杂模式
        up ip link set <span class="token variable">$IFACE</span> promisc on 
        # 给eth0设置固定的mac地址，自己编一个
        hwaddress ether fc:7c:02:4a:bf:21
        # armbian的ip地址
        address 192.168.188.4
        broadcast 192.168.188.255
        netmask 255.255.255.0
        #  主路由的ip地址
        gateway 192.168.188.254
        dns-nameservers 223.5.5.5
        dns-nameservers 114.114.114.114
EOF</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<p>3、重启生效</p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">systemctl <span class="token function">reboot</span><span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>

<h2 id="国内源更换"><a href="#国内源更换" class="headerlink" title="国内源更换"></a>国内源更换</h2><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">cat</span> <span class="token operator">></span> /etc/apt/sources.list <span class="token operator">&lt;&lt;</span> <span class="token string">EOF
# 默认注释了源码仓库，如有需要可自行取消注释
deb https://mirrors.ustc.edu.cn/ubuntu-ports/ jammy main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu-ports/ jammy main main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu-ports/ jammy-updates main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu-ports/ jammy-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu-ports/ jammy-backports main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu-ports/ jammy-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu-ports/ jammy-security main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu-ports/ jammy-security main restricted universe multiverse

# 预发布软件源，不建议启用
# deb https://mirrors.ustc.edu.cn/ubuntu-ports/ jammy-proposed main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu-ports/ jammy-proposed main restricted universe multiverse
EOF</span>

<span class="token function">cat</span> <span class="token operator">></span> /etc/apt/sources.list.d/armbian.list <span class="token operator">&lt;&lt;</span> <span class="token string">EOF
deb [signed-by=/usr/share/keyrings/armbian.gpg] https://mirrors.ustc.edu.cn/armbian jammy main jammy-utils jammy-desktop
EOF</span>

<span class="token function">apt</span> update<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<h2 id="安装常用软件"><a href="#安装常用软件" class="headerlink" title="安装常用软件"></a>安装常用软件</h2><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">apt</span> <span class="token function">install</span> <span class="token function">screen</span> tmux <span class="token function">zip</span> gem  automake autoconf libtool  tldr <span class="token function">htop</span>  iperf3 fio openssl cowsay sl  boxes <span class="token function">strace</span> <span class="token function">mtr</span> <span class="token function">expect</span> telnet sysstat iotop pciutils <span class="token function">lsof</span> <span class="token function">traceroute</span> tcpdump psmisc <span class="token function">bc</span> ntpdate acpid gcc cmake <span class="token function">make</span> <span class="token function">curl</span> <span class="token function">wget</span> <span class="token function">logrotate</span> rsyslog p7zip <span class="token function">sudo</span> nmap dmidecode sdparm net-tools lrzsz <span class="token function">unzip</span> dos2unix bash-completion <span class="token parameter variable">-y</span>

<span class="token function">apt</span> <span class="token function">install</span> ntp chrony<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre>

<h2 id="安装docker"><a href="#安装docker" class="headerlink" title="安装docker"></a>安装docker</h2><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#一路回车就好了</span>
armbian-docker<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre>

<p>安装wireguard</p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">apt</span> <span class="token function">install</span> wireguard resolvconf qrencode <span class="token parameter variable">-y</span><span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>

<p>配置好文件启动就行了</p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">ping</span> <span class="token parameter variable">-c</span> <span class="token number">2</span> <span class="token parameter variable">-i</span> <span class="token number">0.0001</span> <span class="token number">10.10</span>.10.1
<span class="token assign-left variable">tmp_if</span><span class="token operator">=</span><span class="token variable"><span class="token variable">`</span><span class="token builtin class-name">echo</span> $?<span class="token variable">`</span></span>
<span class="token keyword">if</span> <span class="token punctuation">[</span><span class="token punctuation">[</span> <span class="token string">"<span class="token variable">$tmp_if</span>"</span> <span class="token parameter variable">-eq</span> <span class="token number">0</span> <span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">;</span><span class="token keyword">then</span>
  <span class="token builtin class-name">echo</span> ok
<span class="token keyword">else</span>
  wg-quick down wg0
  wg-quick up wg0
<span class="token keyword">fi</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>



<h2 id="安装adguardhome"><a href="#安装adguardhome" class="headerlink" title="安装adguardhome"></a>安装adguardhome</h2><p>脚本安装方法</p>
<h4 id="安装脚本"><a href="#安装脚本" class="headerlink" title="安装脚本"></a>安装脚本</h4><p>vim AdGuard-install.sh</p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token shebang important">#!/bin/sh</span>

<span class="token comment"># AdGuard Home Installation Script</span>

<span class="token comment"># Exit the script if a pipeline fails (-e), prevent accidental filename</span>
<span class="token comment"># expansion (-f), and consider undefined variables as errors (-u).</span>
<span class="token builtin class-name">set</span> <span class="token parameter variable">-e</span> <span class="token parameter variable">-f</span> <span class="token parameter variable">-u</span>

<span class="token comment"># Function log is an echo wrapper that writes to stderr if the caller</span>
<span class="token comment"># requested verbosity level greater than 0.  Otherwise, it does nothing.</span>
<span class="token function-name function">log</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token keyword">if</span> <span class="token punctuation">[</span> <span class="token string">"<span class="token variable">$verbose</span>"</span> <span class="token parameter variable">-gt</span> <span class="token string">'0'</span> <span class="token punctuation">]</span>
        <span class="token keyword">then</span>
                <span class="token builtin class-name">echo</span> <span class="token string">"<span class="token variable">$1</span>"</span> <span class="token operator"><span class="token file-descriptor important">1</span>></span><span class="token file-descriptor important">&amp;2</span>
        <span class="token keyword">fi</span>
<span class="token punctuation">&#125;</span>

<span class="token comment"># Function error_exit is an echo wrapper that writes to stderr and stops the</span>
<span class="token comment"># script execution with code 1.</span>
<span class="token function-name function">error_exit</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token builtin class-name">echo</span> <span class="token string">"<span class="token variable">$1</span>"</span> <span class="token operator"><span class="token file-descriptor important">1</span>></span><span class="token file-descriptor important">&amp;2</span>

        <span class="token builtin class-name">exit</span> <span class="token number">1</span>
<span class="token punctuation">&#125;</span>

<span class="token comment"># Function usage prints the note about how to use the script.</span>
<span class="token comment">#</span>
<span class="token comment"># TODO(e.burkov): Document each option.</span>
<span class="token function-name function">usage</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token builtin class-name">echo</span> <span class="token string">'install.sh: usage: [-c channel] [-C cpu_type] [-h] [-O os] [-o output_dir]'</span><span class="token punctuation">\</span>
                <span class="token string">'[-r|-R] [-u|-U] [-v|-V]'</span> <span class="token operator"><span class="token file-descriptor important">1</span>></span><span class="token file-descriptor important">&amp;2</span>

        <span class="token builtin class-name">exit</span> <span class="token number">2</span>
<span class="token punctuation">&#125;</span>

<span class="token comment"># Function maybe_sudo runs passed command with root privileges if use_sudo isn't</span>
<span class="token comment"># equal to 0.</span>
<span class="token comment">#</span>
<span class="token comment"># TODO(e.burkov):  Use everywhere the sudo_cmd isn't quoted.</span>
<span class="token function-name function">maybe_sudo</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token keyword">if</span> <span class="token punctuation">[</span> <span class="token string">"<span class="token variable">$use_sudo</span>"</span> <span class="token parameter variable">-eq</span> <span class="token number">0</span> <span class="token punctuation">]</span>
        <span class="token keyword">then</span>
                <span class="token string">"<span class="token variable">$@</span>"</span>
        <span class="token keyword">else</span>
                <span class="token string">"<span class="token variable">$sudo_cmd</span>"</span> <span class="token string">"<span class="token variable">$@</span>"</span>
        <span class="token keyword">fi</span>
<span class="token punctuation">&#125;</span>

<span class="token comment"># Function is_command checks if the command exists on the machine.</span>
<span class="token function-name function">is_command</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token builtin class-name">command</span> <span class="token parameter variable">-v</span> <span class="token string">"<span class="token variable">$1</span>"</span> <span class="token operator">></span>/dev/null <span class="token operator"><span class="token file-descriptor important">2</span>></span><span class="token file-descriptor important">&amp;1</span>
<span class="token punctuation">&#125;</span>

<span class="token comment"># Function is_little_endian checks if the CPU is little-endian.</span>
<span class="token comment">#</span>
<span class="token comment"># See https://serverfault.com/a/163493/267530.</span>
<span class="token function-name function">is_little_endian</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token comment"># The ASCII character "I" has the octal code of 111.  In the two-byte octal</span>
        <span class="token comment"># display mode (-o), hexdump will print it either as "000111" on a little</span>
        <span class="token comment"># endian system or as a "111000" on a big endian one.  Return the sixth</span>
        <span class="token comment"># character to compare it against the number '1'.</span>
        <span class="token comment">#</span>
        <span class="token comment"># Do not use echo -n, because its behavior in the presence of the -n flag is</span>
        <span class="token comment"># explicitly implementation-defined in POSIX.  Use hexdump instead of od,</span>
        <span class="token comment"># because OpenWrt and its derivatives have the former but not the latter.</span>
        <span class="token assign-left variable">is_little_endian_result</span><span class="token operator">=</span><span class="token string">"<span class="token variable"><span class="token variable">$(</span>
                <span class="token builtin class-name">printf</span> <span class="token string">'I'</span><span class="token punctuation">\</span>
                        <span class="token operator">|</span> hexdump -o<span class="token punctuation">\</span>
                        <span class="token operator">|</span> <span class="token function">awk</span> <span class="token string">'&#123; print substr($2, 6, 1); exit; &#125;'</span>
        <span class="token variable">)</span></span>"</span>
        <span class="token builtin class-name">readonly</span> is_little_endian_result

        <span class="token punctuation">[</span> <span class="token string">"<span class="token variable">$is_little_endian_result</span>"</span> <span class="token parameter variable">-eq</span> <span class="token string">'1'</span> <span class="token punctuation">]</span>
<span class="token punctuation">&#125;</span>

<span class="token comment"># Function check_required checks if the required software is available on the</span>
<span class="token comment"># machine.  The required software:</span>
<span class="token comment">#</span>
<span class="token comment">#   unzip (macOS) / tar (other unixes)</span>
<span class="token comment">#</span>
<span class="token comment"># curl/wget are checked in function configure.</span>
<span class="token function-name function">check_required</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token assign-left variable">required_darwin</span><span class="token operator">=</span><span class="token string">"unzip"</span>
        <span class="token assign-left variable">required_unix</span><span class="token operator">=</span><span class="token string">"tar"</span>
        <span class="token builtin class-name">readonly</span> required_darwin required_unix

        <span class="token keyword">case</span> <span class="token string">"<span class="token variable">$os</span>"</span>
        <span class="token keyword">in</span>
        <span class="token punctuation">(</span><span class="token string">'freebsd'</span><span class="token operator">|</span><span class="token string">'linux'</span><span class="token operator">|</span><span class="token string">'openbsd'</span><span class="token punctuation">)</span>
                <span class="token assign-left variable">required</span><span class="token operator">=</span><span class="token string">"<span class="token variable">$required_unix</span>"</span>
                <span class="token punctuation">;</span><span class="token punctuation">;</span>
        <span class="token punctuation">(</span><span class="token string">'darwin'</span><span class="token punctuation">)</span>
                <span class="token assign-left variable">required</span><span class="token operator">=</span><span class="token string">"<span class="token variable">$required_darwin</span>"</span>
                <span class="token punctuation">;</span><span class="token punctuation">;</span>
        <span class="token punctuation">(</span>*<span class="token punctuation">)</span>
                <span class="token comment"># Generally shouldn't happen, since the OS has already been validated.</span>
                error_exit <span class="token string">"unsupported operating system: '<span class="token variable">$os</span>'"</span>
                <span class="token punctuation">;</span><span class="token punctuation">;</span>
        <span class="token keyword">esac</span>
        <span class="token builtin class-name">readonly</span> required

        <span class="token comment"># Don't use quotes to get word splitting.</span>
        <span class="token keyword">for</span> <span class="token for-or-select variable">cmd</span> <span class="token keyword">in</span> <span class="token variable">$required</span>
        <span class="token keyword">do</span>
                log <span class="token string">"checking <span class="token variable">$cmd</span>"</span>
                <span class="token keyword">if</span> <span class="token operator">!</span> is_command <span class="token string">"<span class="token variable">$cmd</span>"</span>
                <span class="token keyword">then</span>
                        log <span class="token string">"the full list of required software: [<span class="token variable">$required</span>]"</span>

                        error_exit <span class="token string">"<span class="token variable">$cmd</span> is required to install AdGuard Home via this script"</span>
                <span class="token keyword">fi</span>
        <span class="token keyword">done</span>
<span class="token punctuation">&#125;</span>

<span class="token comment"># Function check_out_dir requires the output directory to be set and exist.</span>
<span class="token function-name function">check_out_dir</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token keyword">if</span> <span class="token punctuation">[</span> <span class="token string">"<span class="token variable">$out_dir</span>"</span> <span class="token operator">=</span> <span class="token string">''</span> <span class="token punctuation">]</span>
        <span class="token keyword">then</span>
                error_exit <span class="token string">'output directory should be presented'</span>
        <span class="token keyword">fi</span>

        <span class="token keyword">if</span> <span class="token operator">!</span> <span class="token punctuation">[</span> <span class="token parameter variable">-d</span> <span class="token string">"<span class="token variable">$out_dir</span>"</span> <span class="token punctuation">]</span>
        <span class="token keyword">then</span>
                log <span class="token string">"<span class="token variable">$out_dir</span> directory will be created"</span>
        <span class="token keyword">fi</span>
<span class="token punctuation">&#125;</span>

<span class="token comment"># Function parse_opts parses the options list and validates it's combinations.</span>
<span class="token function-name function">parse_opts</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token keyword">while</span> <span class="token builtin class-name">getopts</span> <span class="token string">"C:c:hO:o:rRuUvV"</span> opt <span class="token string">"<span class="token variable">$@</span>"</span>
        <span class="token keyword">do</span>
                <span class="token keyword">case</span> <span class="token string">"<span class="token variable">$opt</span>"</span>
                <span class="token keyword">in</span>
                <span class="token punctuation">(</span>C<span class="token punctuation">)</span>
                        <span class="token assign-left variable">cpu</span><span class="token operator">=</span><span class="token string">"<span class="token variable">$OPTARG</span>"</span>
                        <span class="token punctuation">;</span><span class="token punctuation">;</span>
                <span class="token punctuation">(</span>c<span class="token punctuation">)</span>
                        <span class="token assign-left variable">channel</span><span class="token operator">=</span><span class="token string">"<span class="token variable">$OPTARG</span>"</span>
                        <span class="token punctuation">;</span><span class="token punctuation">;</span>
                <span class="token punctuation">(</span>h<span class="token punctuation">)</span>
                        usage
                        <span class="token punctuation">;</span><span class="token punctuation">;</span>
                <span class="token punctuation">(</span>O<span class="token punctuation">)</span>
                        <span class="token assign-left variable">os</span><span class="token operator">=</span><span class="token string">"<span class="token variable">$OPTARG</span>"</span>
                        <span class="token punctuation">;</span><span class="token punctuation">;</span>
                <span class="token punctuation">(</span>o<span class="token punctuation">)</span>
                        <span class="token assign-left variable">out_dir</span><span class="token operator">=</span><span class="token string">"<span class="token variable">$OPTARG</span>"</span>
                        <span class="token punctuation">;</span><span class="token punctuation">;</span>
                <span class="token punctuation">(</span>R<span class="token punctuation">)</span>
                        <span class="token assign-left variable">reinstall</span><span class="token operator">=</span><span class="token string">'0'</span>
                        <span class="token punctuation">;</span><span class="token punctuation">;</span>
                <span class="token punctuation">(</span>U<span class="token punctuation">)</span>
                        <span class="token assign-left variable">uninstall</span><span class="token operator">=</span><span class="token string">'0'</span>
                        <span class="token punctuation">;</span><span class="token punctuation">;</span>
                <span class="token punctuation">(</span>r<span class="token punctuation">)</span>
                        <span class="token assign-left variable">reinstall</span><span class="token operator">=</span><span class="token string">'1'</span>
                        <span class="token punctuation">;</span><span class="token punctuation">;</span>
                <span class="token punctuation">(</span>u<span class="token punctuation">)</span>
                        <span class="token assign-left variable">uninstall</span><span class="token operator">=</span><span class="token string">'1'</span>
                        <span class="token punctuation">;</span><span class="token punctuation">;</span>
                <span class="token punctuation">(</span>V<span class="token punctuation">)</span>
                        <span class="token assign-left variable">verbose</span><span class="token operator">=</span><span class="token string">'0'</span>
                        <span class="token punctuation">;</span><span class="token punctuation">;</span>
                <span class="token punctuation">(</span>v<span class="token punctuation">)</span>
                        <span class="token assign-left variable">verbose</span><span class="token operator">=</span><span class="token string">'1'</span>
                        <span class="token punctuation">;</span><span class="token punctuation">;</span>
                <span class="token punctuation">(</span>*<span class="token punctuation">)</span>
                        log <span class="token string">"bad option <span class="token variable">$OPTARG</span>"</span>

                        usage
                        <span class="token punctuation">;</span><span class="token punctuation">;</span>
                <span class="token keyword">esac</span>
        <span class="token keyword">done</span>

        <span class="token keyword">if</span> <span class="token punctuation">[</span> <span class="token string">"<span class="token variable">$uninstall</span>"</span> <span class="token parameter variable">-eq</span> <span class="token string">'1'</span> <span class="token punctuation">]</span> <span class="token operator">&amp;&amp;</span> <span class="token punctuation">[</span> <span class="token string">"<span class="token variable">$reinstall</span>"</span> <span class="token parameter variable">-eq</span> <span class="token string">'1'</span> <span class="token punctuation">]</span>
        <span class="token keyword">then</span>
                error_exit <span class="token string">'the -r and -u options are mutually exclusive'</span>
        <span class="token keyword">fi</span>
<span class="token punctuation">&#125;</span>

<span class="token comment"># Function set_channel sets the channel if needed and validates the value.</span>
<span class="token function-name function">set_channel</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token comment"># Validate.</span>
        <span class="token keyword">case</span> <span class="token string">"<span class="token variable">$channel</span>"</span>
        <span class="token keyword">in</span>
        <span class="token punctuation">(</span><span class="token string">'development'</span><span class="token operator">|</span><span class="token string">'edge'</span><span class="token operator">|</span><span class="token string">'beta'</span><span class="token operator">|</span><span class="token string">'release'</span><span class="token punctuation">)</span>
                <span class="token comment"># All is well, go on.</span>
                <span class="token punctuation">;</span><span class="token punctuation">;</span>
        <span class="token punctuation">(</span>*<span class="token punctuation">)</span>
                error_exit <span class="token punctuation">\</span>
<span class="token string">"invalid channel '<span class="token variable">$channel</span>'
supported values are 'development', 'edge', 'beta', and 'release'"</span>
                <span class="token punctuation">;</span><span class="token punctuation">;</span>
        <span class="token keyword">esac</span>

        <span class="token comment"># Log.</span>
        log <span class="token string">"channel: <span class="token variable">$channel</span>"</span>
<span class="token punctuation">&#125;</span>

<span class="token comment"># Function set_os sets the os if needed and validates the value.</span>
<span class="token function-name function">set_os</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token comment"># Set if needed.</span>
        <span class="token keyword">if</span> <span class="token punctuation">[</span> <span class="token string">"<span class="token variable">$os</span>"</span> <span class="token operator">=</span> <span class="token string">''</span> <span class="token punctuation">]</span>
        <span class="token keyword">then</span>
                <span class="token assign-left variable">os</span><span class="token operator">=</span><span class="token string">"<span class="token variable"><span class="token variable">$(</span> <span class="token function">uname</span> <span class="token parameter variable">-s</span> <span class="token variable">)</span></span>"</span>
                <span class="token keyword">case</span> <span class="token string">"<span class="token variable">$os</span>"</span>
                <span class="token keyword">in</span>
                <span class="token punctuation">(</span><span class="token string">'Darwin'</span><span class="token punctuation">)</span>
                        <span class="token assign-left variable">os</span><span class="token operator">=</span><span class="token string">'darwin'</span>
                        <span class="token punctuation">;</span><span class="token punctuation">;</span>
                <span class="token punctuation">(</span><span class="token string">'FreeBSD'</span><span class="token punctuation">)</span>
                        <span class="token assign-left variable">os</span><span class="token operator">=</span><span class="token string">'freebsd'</span>
                        <span class="token punctuation">;</span><span class="token punctuation">;</span>
                <span class="token punctuation">(</span><span class="token string">'Linux'</span><span class="token punctuation">)</span>
                        <span class="token assign-left variable">os</span><span class="token operator">=</span><span class="token string">'linux'</span>
                        <span class="token punctuation">;</span><span class="token punctuation">;</span>
                <span class="token punctuation">(</span><span class="token string">'OpenBSD'</span><span class="token punctuation">)</span>
                        <span class="token assign-left variable">os</span><span class="token operator">=</span><span class="token string">'openbsd'</span>
                        <span class="token punctuation">;</span><span class="token punctuation">;</span>
                <span class="token punctuation">(</span>*<span class="token punctuation">)</span>
                        error_exit <span class="token string">"unsupported operating system: '<span class="token variable">$os</span>'"</span>
                        <span class="token punctuation">;</span><span class="token punctuation">;</span>
                <span class="token keyword">esac</span>
        <span class="token keyword">fi</span>

        <span class="token comment"># Validate.</span>
        <span class="token keyword">case</span> <span class="token string">"<span class="token variable">$os</span>"</span>
        <span class="token keyword">in</span>
        <span class="token punctuation">(</span><span class="token string">'darwin'</span><span class="token operator">|</span><span class="token string">'freebsd'</span><span class="token operator">|</span><span class="token string">'linux'</span><span class="token operator">|</span><span class="token string">'openbsd'</span><span class="token punctuation">)</span>
                <span class="token comment"># All right, go on.</span>
                <span class="token punctuation">;</span><span class="token punctuation">;</span>
        <span class="token punctuation">(</span>*<span class="token punctuation">)</span>
                error_exit <span class="token string">"unsupported operating system: '<span class="token variable">$os</span>'"</span>
                <span class="token punctuation">;</span><span class="token punctuation">;</span>
        <span class="token keyword">esac</span>

        <span class="token comment"># Log.</span>
        log <span class="token string">"operating system: <span class="token variable">$os</span>"</span>
<span class="token punctuation">&#125;</span>

<span class="token comment"># Function set_cpu sets the cpu if needed and validates the value.</span>
<span class="token function-name function">set_cpu</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token comment"># Set if needed.</span>
        <span class="token keyword">if</span> <span class="token punctuation">[</span> <span class="token string">"<span class="token variable">$cpu</span>"</span> <span class="token operator">=</span> <span class="token string">''</span> <span class="token punctuation">]</span>
        <span class="token keyword">then</span>
                <span class="token assign-left variable">cpu</span><span class="token operator">=</span><span class="token string">"<span class="token variable"><span class="token variable">$(</span> <span class="token function">uname</span> <span class="token parameter variable">-m</span> <span class="token variable">)</span></span>"</span>
                <span class="token keyword">case</span> <span class="token string">"<span class="token variable">$cpu</span>"</span>
                <span class="token keyword">in</span>
                <span class="token punctuation">(</span><span class="token string">'x86_64'</span><span class="token operator">|</span><span class="token string">'x86-64'</span><span class="token operator">|</span><span class="token string">'x64'</span><span class="token operator">|</span><span class="token string">'amd64'</span><span class="token punctuation">)</span>
                        <span class="token assign-left variable">cpu</span><span class="token operator">=</span><span class="token string">'amd64'</span>
                        <span class="token punctuation">;</span><span class="token punctuation">;</span>
                <span class="token punctuation">(</span><span class="token string">'i386'</span><span class="token operator">|</span><span class="token string">'i486'</span><span class="token operator">|</span><span class="token string">'i686'</span><span class="token operator">|</span><span class="token string">'i786'</span><span class="token operator">|</span><span class="token string">'x86'</span><span class="token punctuation">)</span>
                        <span class="token assign-left variable">cpu</span><span class="token operator">=</span><span class="token string">'386'</span>
                        <span class="token punctuation">;</span><span class="token punctuation">;</span>
                <span class="token punctuation">(</span><span class="token string">'armv5l'</span><span class="token punctuation">)</span>
                        <span class="token assign-left variable">cpu</span><span class="token operator">=</span><span class="token string">'armv5'</span>
                        <span class="token punctuation">;</span><span class="token punctuation">;</span>
                <span class="token punctuation">(</span><span class="token string">'armv6l'</span><span class="token punctuation">)</span>
                        <span class="token assign-left variable">cpu</span><span class="token operator">=</span><span class="token string">'armv6'</span>
                        <span class="token punctuation">;</span><span class="token punctuation">;</span>
                <span class="token punctuation">(</span><span class="token string">'armv7l'</span> <span class="token operator">|</span> <span class="token string">'armv8l'</span><span class="token punctuation">)</span>
                        <span class="token assign-left variable">cpu</span><span class="token operator">=</span><span class="token string">'armv7'</span>
                        <span class="token punctuation">;</span><span class="token punctuation">;</span>
                <span class="token punctuation">(</span><span class="token string">'aarch64'</span><span class="token operator">|</span><span class="token string">'arm64'</span><span class="token punctuation">)</span>
                        <span class="token assign-left variable">cpu</span><span class="token operator">=</span><span class="token string">'arm64'</span>
                        <span class="token punctuation">;</span><span class="token punctuation">;</span>
                <span class="token punctuation">(</span><span class="token string">'mips'</span><span class="token operator">|</span><span class="token string">'mips64'</span><span class="token punctuation">)</span>
                        <span class="token keyword">if</span> is_little_endian
                        <span class="token keyword">then</span>
                                <span class="token assign-left variable">cpu</span><span class="token operator">=</span><span class="token string">"<span class="token variable">$&#123;cpu&#125;</span>le"</span>
                        <span class="token keyword">fi</span>
                        <span class="token assign-left variable">cpu</span><span class="token operator">=</span><span class="token string">"<span class="token variable">$&#123;cpu&#125;</span>_softfloat"</span>
                        <span class="token punctuation">;</span><span class="token punctuation">;</span>
                <span class="token punctuation">(</span>*<span class="token punctuation">)</span>
                        error_exit <span class="token string">"unsupported cpu type: <span class="token variable">$cpu</span>"</span>
                        <span class="token punctuation">;</span><span class="token punctuation">;</span>
                <span class="token keyword">esac</span>
        <span class="token keyword">fi</span>

        <span class="token comment"># Validate.</span>
        <span class="token keyword">case</span> <span class="token string">"<span class="token variable">$cpu</span>"</span>
        <span class="token keyword">in</span>
        <span class="token punctuation">(</span><span class="token string">'amd64'</span><span class="token operator">|</span><span class="token string">'386'</span><span class="token operator">|</span><span class="token string">'armv5'</span><span class="token operator">|</span><span class="token string">'armv6'</span><span class="token operator">|</span><span class="token string">'armv7'</span><span class="token operator">|</span><span class="token string">'arm64'</span><span class="token punctuation">)</span>
                <span class="token comment"># All right, go on.</span>
                <span class="token punctuation">;</span><span class="token punctuation">;</span>
        <span class="token punctuation">(</span><span class="token string">'mips64le_softfloat'</span><span class="token operator">|</span><span class="token string">'mips64_softfloat'</span><span class="token operator">|</span><span class="token string">'mipsle_softfloat'</span><span class="token operator">|</span><span class="token string">'mips_softfloat'</span><span class="token punctuation">)</span>
                <span class="token comment"># That's right too.</span>
                <span class="token punctuation">;</span><span class="token punctuation">;</span>
        <span class="token punctuation">(</span>*<span class="token punctuation">)</span>
                error_exit <span class="token string">"unsupported cpu type: <span class="token variable">$cpu</span>"</span>
                <span class="token punctuation">;</span><span class="token punctuation">;</span>
        <span class="token keyword">esac</span>

        <span class="token comment"># Log.</span>
        log <span class="token string">"cpu type: <span class="token variable">$cpu</span>"</span>
<span class="token punctuation">&#125;</span>

<span class="token comment"># Function fix_darwin performs some configuration changes for macOS if needed.</span>
<span class="token comment">#</span>
<span class="token comment"># TODO(a.garipov): Remove after the final v0.107.0 release.</span>
<span class="token comment">#</span>
<span class="token comment"># See https://github.com/AdguardTeam/AdGuardHome/issues/2443.</span>
<span class="token function-name function">fix_darwin</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token keyword">if</span> <span class="token punctuation">[</span> <span class="token string">"<span class="token variable">$os</span>"</span> <span class="token operator">!=</span> <span class="token string">'darwin'</span> <span class="token punctuation">]</span>
        <span class="token keyword">then</span>
                <span class="token builtin class-name">return</span> <span class="token number">0</span>
        <span class="token keyword">fi</span>

        <span class="token comment"># Set the package extension.</span>
        <span class="token assign-left variable">pkg_ext</span><span class="token operator">=</span><span class="token string">'zip'</span>

        <span class="token comment"># It is important to install AdGuard Home into the /Applications directory</span>
        <span class="token comment"># on macOS.  Otherwise, it may grant not enough privileges to the AdGuard</span>
        <span class="token comment"># Home.</span>
        <span class="token assign-left variable">out_dir</span><span class="token operator">=</span><span class="token string">'/Applications'</span>
<span class="token punctuation">&#125;</span>

<span class="token comment"># Function fix_freebsd performs some fixes to make it work on FreeBSD.</span>
<span class="token function-name function">fix_freebsd</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token keyword">if</span> <span class="token operator">!</span> <span class="token punctuation">[</span> <span class="token string">"<span class="token variable">$os</span>"</span> <span class="token operator">=</span> <span class="token string">'freebsd'</span> <span class="token punctuation">]</span>
        <span class="token keyword">then</span>
                <span class="token builtin class-name">return</span> <span class="token number">0</span>
        <span class="token keyword">fi</span>

        <span class="token assign-left variable">rcd</span><span class="token operator">=</span><span class="token string">'/usr/local/etc/rc.d'</span>
        <span class="token builtin class-name">readonly</span> rcd

        <span class="token keyword">if</span> <span class="token operator">!</span> <span class="token punctuation">[</span> <span class="token parameter variable">-d</span> <span class="token string">"<span class="token variable">$rcd</span>"</span> <span class="token punctuation">]</span>
        <span class="token keyword">then</span>
                <span class="token function">mkdir</span> <span class="token string">"<span class="token variable">$rcd</span>"</span>
        <span class="token keyword">fi</span>
<span class="token punctuation">&#125;</span>

<span class="token comment"># download_curl uses curl(1) to download a file.  The first argument is the URL.</span>
<span class="token comment"># The second argument is optional and is the output file.</span>
<span class="token function-name function">download_curl</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token assign-left variable">curl_output</span><span class="token operator">=</span><span class="token string">"<span class="token variable">$&#123;2<span class="token operator">:-</span>&#125;</span>"</span>
        <span class="token keyword">if</span> <span class="token punctuation">[</span> <span class="token string">"<span class="token variable">$curl_output</span>"</span> <span class="token operator">=</span> <span class="token string">''</span> <span class="token punctuation">]</span>
        <span class="token keyword">then</span>
                <span class="token function">curl</span> <span class="token parameter variable">-L</span> <span class="token parameter variable">-S</span> <span class="token parameter variable">-s</span> <span class="token string">"<span class="token variable">$1</span>"</span>
        <span class="token keyword">else</span>
                <span class="token function">curl</span> <span class="token parameter variable">-L</span> <span class="token parameter variable">-S</span> <span class="token parameter variable">-o</span> <span class="token string">"<span class="token variable">$curl_output</span>"</span> <span class="token parameter variable">-s</span> <span class="token string">"<span class="token variable">$1</span>"</span>
        <span class="token keyword">fi</span>
<span class="token punctuation">&#125;</span>

<span class="token comment"># download_wget uses wget(1) to download a file.  The first argument is the URL.</span>
<span class="token comment"># The second argument is optional and is the output file.</span>
<span class="token function-name function">download_wget</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token assign-left variable">wget_output</span><span class="token operator">=</span><span class="token string">"<span class="token variable">$&#123;2<span class="token operator">:-</span>-&#125;</span>"</span>

        <span class="token function">wget</span> --no-verbose <span class="token parameter variable">-O</span> <span class="token string">"<span class="token variable">$wget_output</span>"</span> <span class="token string">"<span class="token variable">$1</span>"</span>
<span class="token punctuation">&#125;</span>

<span class="token comment"># download_fetch uses fetch(1) to download a file.  The first argument is the</span>
<span class="token comment"># URL.  The second argument is optional and is the output file.</span>
<span class="token function-name function">download_fetch</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token assign-left variable">fetch_output</span><span class="token operator">=</span><span class="token string">"<span class="token variable">$&#123;2<span class="token operator">:-</span>&#125;</span>"</span>
        <span class="token keyword">if</span> <span class="token punctuation">[</span> <span class="token string">"<span class="token variable">$fetch_output</span>"</span> <span class="token operator">=</span> <span class="token string">''</span> <span class="token punctuation">]</span>
        <span class="token keyword">then</span>
                fetch <span class="token parameter variable">-o</span> <span class="token string">'-'</span> <span class="token string">"<span class="token variable">$1</span>"</span>
        <span class="token keyword">else</span>
                fetch <span class="token parameter variable">-o</span> <span class="token string">"<span class="token variable">$fetch_output</span>"</span> <span class="token string">"<span class="token variable">$1</span>"</span>
        <span class="token keyword">fi</span>
<span class="token punctuation">&#125;</span>

<span class="token comment"># Function set_download_func sets the appropriate function for downloading</span>
<span class="token comment"># files.</span>
<span class="token function-name function">set_download_func</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token keyword">if</span> is_command <span class="token string">'curl'</span>
        <span class="token keyword">then</span>
                <span class="token comment"># Go on and use the default, download_curl.</span>
                <span class="token builtin class-name">return</span> <span class="token number">0</span>
        <span class="token keyword">elif</span> is_command <span class="token string">'wget'</span>
        <span class="token keyword">then</span>
                <span class="token assign-left variable">download_func</span><span class="token operator">=</span><span class="token string">'download_wget'</span>
        <span class="token keyword">elif</span> is_command <span class="token string">'fetch'</span>
        <span class="token keyword">then</span>
                <span class="token assign-left variable">download_func</span><span class="token operator">=</span><span class="token string">'download_fetch'</span>
        <span class="token keyword">else</span>
                error_exit <span class="token string">"either curl or wget is required to install AdGuard Home via this script"</span>
        <span class="token keyword">fi</span>
<span class="token punctuation">&#125;</span>

<span class="token comment"># Function set_sudo_cmd sets the appropriate command to run a command under</span>
<span class="token comment"># superuser privileges.</span>
<span class="token function-name function">set_sudo_cmd</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token keyword">case</span> <span class="token string">"<span class="token variable">$os</span>"</span>
        <span class="token keyword">in</span>
        <span class="token punctuation">(</span><span class="token string">'openbsd'</span><span class="token punctuation">)</span>
                <span class="token assign-left variable">sudo_cmd</span><span class="token operator">=</span><span class="token string">'doas'</span>
                <span class="token punctuation">;</span><span class="token punctuation">;</span>
        <span class="token punctuation">(</span><span class="token string">'darwin'</span><span class="token operator">|</span><span class="token string">'freebsd'</span><span class="token operator">|</span><span class="token string">'linux'</span><span class="token punctuation">)</span>
                <span class="token comment"># Go on and use the default, sudo.</span>
                <span class="token punctuation">;</span><span class="token punctuation">;</span>
        <span class="token punctuation">(</span>*<span class="token punctuation">)</span>
                error_exit <span class="token string">"unsupported operating system: '<span class="token variable">$os</span>'"</span>
                <span class="token punctuation">;</span><span class="token punctuation">;</span>
        <span class="token keyword">esac</span>
<span class="token punctuation">&#125;</span>

<span class="token comment"># Function configure sets the script's configuration.</span>
<span class="token function-name function">configure</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        set_channel
        set_os
        set_cpu
        fix_darwin
        set_download_func
        set_sudo_cmd
        check_out_dir

        <span class="token assign-left variable">pkg_name</span><span class="token operator">=</span><span class="token string">"AdGuardHome_<span class="token variable">$&#123;os&#125;</span>_<span class="token variable">$&#123;cpu&#125;</span>.<span class="token variable">$&#123;pkg_ext&#125;</span>"</span>
        <span class="token assign-left variable">url</span><span class="token operator">=</span><span class="token string">"https://static.adtidy.org/adguardhome/<span class="token variable">$&#123;channel&#125;</span>/<span class="token variable">$&#123;pkg_name&#125;</span>"</span>
        <span class="token assign-left variable">agh_dir</span><span class="token operator">=</span><span class="token string">"<span class="token variable">$&#123;out_dir&#125;</span>/AdGuardHome"</span>
        <span class="token builtin class-name">readonly</span> pkg_name url agh_dir

        log <span class="token string">"AdGuard Home will be installed into <span class="token variable">$agh_dir</span>"</span>
<span class="token punctuation">&#125;</span>

<span class="token comment"># Function is_root checks for root privileges to be granted.</span>
<span class="token function-name function">is_root</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token keyword">if</span> <span class="token punctuation">[</span> <span class="token string">"<span class="token variable"><span class="token variable">$(</span> <span class="token function">id</span> <span class="token parameter variable">-u</span> <span class="token variable">)</span></span>"</span> <span class="token parameter variable">-eq</span> <span class="token string">'0'</span> <span class="token punctuation">]</span>
        <span class="token keyword">then</span>
                log <span class="token string">'script is executed with root privileges'</span>

                <span class="token builtin class-name">return</span> <span class="token number">0</span>
        <span class="token keyword">fi</span>

        <span class="token keyword">if</span> is_command <span class="token string">"<span class="token variable">$sudo_cmd</span>"</span>
        <span class="token keyword">then</span>
                log <span class="token string">'note that AdGuard Home requires root privileges to install using this script'</span>

                <span class="token builtin class-name">return</span> <span class="token number">1</span>
        <span class="token keyword">fi</span>

        error_exit <span class="token punctuation">\</span>
<span class="token string">'root privileges are required to install AdGuard Home using this script
please, restart it with root privileges'</span>
<span class="token punctuation">&#125;</span>

<span class="token comment"># Function rerun_with_root downloads the script, runs it with root privileges,</span>
<span class="token comment"># and exits the current script.  It passes the necessary configuration of the</span>
<span class="token comment"># current script to the child script.</span>
<span class="token comment">#</span>
<span class="token comment"># TODO(e.burkov): Try to avoid restarting.</span>
<span class="token function-name function">rerun_with_root</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token assign-left variable">script_url</span><span class="token operator">=</span><span class="token punctuation">\</span>
<span class="token string">'https://raw.githubusercontent.com/AdguardTeam/AdGuardHome/master/scripts/install.sh'</span>
        <span class="token builtin class-name">readonly</span> script_url

        <span class="token assign-left variable">r</span><span class="token operator">=</span><span class="token string">'-R'</span>
        <span class="token keyword">if</span> <span class="token punctuation">[</span> <span class="token string">"<span class="token variable">$reinstall</span>"</span> <span class="token parameter variable">-eq</span> <span class="token string">'1'</span> <span class="token punctuation">]</span>
        <span class="token keyword">then</span>
                <span class="token assign-left variable">r</span><span class="token operator">=</span><span class="token string">'-r'</span>
        <span class="token keyword">fi</span>

        <span class="token assign-left variable">u</span><span class="token operator">=</span><span class="token string">'-U'</span>
        <span class="token keyword">if</span> <span class="token punctuation">[</span> <span class="token string">"<span class="token variable">$uninstall</span>"</span> <span class="token parameter variable">-eq</span> <span class="token string">'1'</span> <span class="token punctuation">]</span>
        <span class="token keyword">then</span>
                <span class="token assign-left variable">u</span><span class="token operator">=</span><span class="token string">'-u'</span>
        <span class="token keyword">fi</span>

        <span class="token assign-left variable">v</span><span class="token operator">=</span><span class="token string">'-V'</span>
        <span class="token keyword">if</span> <span class="token punctuation">[</span> <span class="token string">"<span class="token variable">$verbose</span>"</span> <span class="token parameter variable">-eq</span> <span class="token string">'1'</span> <span class="token punctuation">]</span>
        <span class="token keyword">then</span>
                <span class="token assign-left variable">v</span><span class="token operator">=</span><span class="token string">'-v'</span>
        <span class="token keyword">fi</span>

        <span class="token builtin class-name">readonly</span> r u <span class="token function">v</span>

        log <span class="token string">'restarting with root privileges'</span>

        <span class="token comment"># Group curl/wget together with an echo, so that if the former fails before</span>
        <span class="token comment"># producing any output, the latter prints an exit command for the following</span>
        <span class="token comment"># shell to execute to prevent it from getting an empty input and exiting</span>
        <span class="token comment"># with a zero code in that case.</span>
        <span class="token punctuation">&#123;</span> <span class="token string">"<span class="token variable">$download_func</span>"</span> <span class="token string">"<span class="token variable">$script_url</span>"</span> <span class="token operator">||</span> <span class="token builtin class-name">echo</span> <span class="token string">'exit 1'</span><span class="token punctuation">;</span> <span class="token punctuation">&#125;</span><span class="token punctuation">\</span>
                <span class="token operator">|</span> <span class="token variable">$sudo_cmd</span> <span class="token function">sh</span> <span class="token parameter variable">-s</span> -- <span class="token parameter variable">-c</span> <span class="token string">"<span class="token variable">$channel</span>"</span> <span class="token parameter variable">-C</span> <span class="token string">"<span class="token variable">$cpu</span>"</span> <span class="token parameter variable">-O</span> <span class="token string">"<span class="token variable">$os</span>"</span> <span class="token parameter variable">-o</span> <span class="token string">"<span class="token variable">$out_dir</span>"</span> <span class="token string">"<span class="token variable">$r</span>"</span> <span class="token string">"<span class="token variable">$u</span>"</span> <span class="token string">"<span class="token variable">$v</span>"</span>

        <span class="token comment"># Exit the script.  Since if the code of the previous pipeline is non-zero,</span>
        <span class="token comment"># the execution won't reach this point thanks to set -e, exit with zero.</span>
        <span class="token builtin class-name">exit</span> <span class="token number">0</span>
<span class="token punctuation">&#125;</span>

<span class="token comment"># Function download downloads the file from the URL and saves it to the</span>
<span class="token comment"># specified filepath.</span>
<span class="token function-name function">download</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        log <span class="token string">"downloading package from <span class="token variable">$url</span> -> <span class="token variable">$pkg_name</span>"</span>

        <span class="token keyword">if</span> <span class="token operator">!</span> <span class="token string">"<span class="token variable">$download_func</span>"</span> <span class="token string">"<span class="token variable">$url</span>"</span> <span class="token string">"<span class="token variable">$pkg_name</span>"</span>
        <span class="token keyword">then</span>
                error_exit <span class="token string">"cannot download the package from <span class="token variable">$url</span> into <span class="token variable">$pkg_name</span>"</span>
        <span class="token keyword">fi</span>

        log <span class="token string">"successfully downloaded <span class="token variable">$pkg_name</span>"</span>
<span class="token punctuation">&#125;</span>

<span class="token comment"># Function unpack unpacks the passed archive depending on it's extension.</span>
<span class="token function-name function">unpack</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        log <span class="token string">"unpacking package from <span class="token variable">$pkg_name</span> into <span class="token variable">$out_dir</span>"</span>
        <span class="token keyword">if</span> <span class="token operator">!</span> <span class="token function">mkdir</span> <span class="token parameter variable">-p</span> <span class="token string">"<span class="token variable">$out_dir</span>"</span>
        <span class="token keyword">then</span>
                error_exit <span class="token string">"cannot create directory <span class="token variable">$out_dir</span>"</span>
        <span class="token keyword">fi</span>

        <span class="token keyword">case</span> <span class="token string">"<span class="token variable">$pkg_ext</span>"</span>
        <span class="token keyword">in</span>
        <span class="token punctuation">(</span><span class="token string">'zip'</span><span class="token punctuation">)</span>
                <span class="token function">unzip</span> <span class="token string">"<span class="token variable">$pkg_name</span>"</span> <span class="token parameter variable">-d</span> <span class="token string">"<span class="token variable">$out_dir</span>"</span>
                <span class="token punctuation">;</span><span class="token punctuation">;</span>
        <span class="token punctuation">(</span><span class="token string">'tar.gz'</span><span class="token punctuation">)</span>
                <span class="token function">tar</span> <span class="token parameter variable">-C</span> <span class="token string">"<span class="token variable">$out_dir</span>"</span> <span class="token parameter variable">-f</span> <span class="token string">"<span class="token variable">$pkg_name</span>"</span> <span class="token parameter variable">-x</span> <span class="token parameter variable">-z</span>
                <span class="token punctuation">;</span><span class="token punctuation">;</span>
        <span class="token punctuation">(</span>*<span class="token punctuation">)</span>
                error_exit <span class="token string">"unexpected package extension: '<span class="token variable">$pkg_ext</span>'"</span>
                <span class="token punctuation">;</span><span class="token punctuation">;</span>
        <span class="token keyword">esac</span>

        log <span class="token string">"successfully unpacked, contents: <span class="token variable"><span class="token variable">$(</span> <span class="token builtin class-name">echo</span><span class="token punctuation">;</span> <span class="token function">ls</span> <span class="token parameter variable">-l</span> <span class="token parameter variable">-A</span> <span class="token string">"<span class="token variable">$agh_dir</span>"</span> <span class="token variable">)</span></span>"</span>

        <span class="token function">rm</span> <span class="token string">"<span class="token variable">$pkg_name</span>"</span>
<span class="token punctuation">&#125;</span>

<span class="token comment"># Function handle_existing detects the existing AGH installation and takes care</span>
<span class="token comment"># of removing it if needed.</span>
<span class="token function-name function">handle_existing</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token keyword">if</span> <span class="token operator">!</span> <span class="token punctuation">[</span> <span class="token parameter variable">-d</span> <span class="token string">"<span class="token variable">$agh_dir</span>"</span> <span class="token punctuation">]</span>
        <span class="token keyword">then</span>
                log <span class="token string">'no need to uninstall'</span>

                <span class="token keyword">if</span> <span class="token punctuation">[</span> <span class="token string">"<span class="token variable">$uninstall</span>"</span> <span class="token parameter variable">-eq</span> <span class="token string">'1'</span> <span class="token punctuation">]</span>
                <span class="token keyword">then</span>
                        <span class="token builtin class-name">exit</span> <span class="token number">0</span>
                <span class="token keyword">fi</span>

                <span class="token builtin class-name">return</span> <span class="token number">0</span>
        <span class="token keyword">fi</span>

        <span class="token keyword">if</span> <span class="token punctuation">[</span> <span class="token string">"<span class="token variable"><span class="token variable">$(</span> <span class="token function">ls</span> <span class="token parameter variable">-1</span> <span class="token parameter variable">-A</span> <span class="token string">"<span class="token variable">$agh_dir</span>"</span> <span class="token variable">)</span></span>"</span> <span class="token operator">!=</span> <span class="token string">''</span> <span class="token punctuation">]</span>
        <span class="token keyword">then</span>
                log <span class="token string">'the existing AdGuard Home installation is detected'</span>

                <span class="token keyword">if</span> <span class="token punctuation">[</span> <span class="token string">"<span class="token variable">$reinstall</span>"</span> <span class="token parameter variable">-ne</span> <span class="token string">'1'</span> <span class="token punctuation">]</span> <span class="token operator">&amp;&amp;</span> <span class="token punctuation">[</span> <span class="token string">"<span class="token variable">$uninstall</span>"</span> <span class="token parameter variable">-ne</span> <span class="token string">'1'</span> <span class="token punctuation">]</span>
                <span class="token keyword">then</span>
                        error_exit <span class="token punctuation">\</span>
<span class="token string">"to reinstall/uninstall the AdGuard Home using this script specify one of the '-r' or '-u' flags"</span>
                <span class="token keyword">fi</span>

                <span class="token comment"># TODO(e.burkov):  Remove the stop once v0.107.1 released.</span>
                <span class="token keyword">if</span> <span class="token punctuation">(</span> <span class="token builtin class-name">cd</span> <span class="token string">"<span class="token variable">$agh_dir</span>"</span> <span class="token operator">&amp;&amp;</span> <span class="token operator">!</span> ./AdGuardHome <span class="token parameter variable">-s</span> stop <span class="token operator">||</span> <span class="token operator">!</span> ./AdGuardHome <span class="token parameter variable">-s</span> uninstall <span class="token punctuation">)</span>
                <span class="token keyword">then</span>
                        <span class="token comment"># It doesn't terminate the script since it is possible</span>
                        <span class="token comment"># that AGH just not installed as service but appearing</span>
                        <span class="token comment"># in the directory.</span>
                        log <span class="token string">"cannot uninstall AdGuard Home from <span class="token variable">$agh_dir</span>"</span>
                <span class="token keyword">fi</span>

                <span class="token function">rm</span> <span class="token parameter variable">-r</span> <span class="token string">"<span class="token variable">$agh_dir</span>"</span>

                log <span class="token string">'AdGuard Home was successfully uninstalled'</span>
        <span class="token keyword">fi</span>

        <span class="token keyword">if</span> <span class="token punctuation">[</span> <span class="token string">"<span class="token variable">$uninstall</span>"</span> <span class="token parameter variable">-eq</span> <span class="token string">'1'</span> <span class="token punctuation">]</span>
        <span class="token keyword">then</span>
                <span class="token builtin class-name">exit</span> <span class="token number">0</span>
        <span class="token keyword">fi</span>
<span class="token punctuation">&#125;</span>

<span class="token comment"># Function install_service tries to install AGH as service.</span>
<span class="token function-name function">install_service</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token comment"># Installing the service as root is required at least on FreeBSD.</span>
        <span class="token assign-left variable">use_sudo</span><span class="token operator">=</span><span class="token string">'0'</span>
        <span class="token keyword">if</span> <span class="token punctuation">[</span> <span class="token string">"<span class="token variable">$os</span>"</span> <span class="token operator">=</span> <span class="token string">'freebsd'</span> <span class="token punctuation">]</span>
        <span class="token keyword">then</span>
                <span class="token assign-left variable">use_sudo</span><span class="token operator">=</span><span class="token string">'1'</span>
        <span class="token keyword">fi</span>

        <span class="token keyword">if</span> <span class="token punctuation">(</span> <span class="token builtin class-name">cd</span> <span class="token string">"<span class="token variable">$agh_dir</span>"</span> <span class="token operator">&amp;&amp;</span> maybe_sudo ./AdGuardHome <span class="token parameter variable">-s</span> <span class="token function">install</span> <span class="token punctuation">)</span>
        <span class="token keyword">then</span>
                <span class="token builtin class-name">return</span> <span class="token number">0</span>
        <span class="token keyword">fi</span>

        log <span class="token string">"installation failed, removing <span class="token variable">$agh_dir</span>"</span>

        <span class="token function">rm</span> <span class="token parameter variable">-r</span> <span class="token string">"<span class="token variable">$agh_dir</span>"</span>

        <span class="token comment"># Some devices detected to have armv7 CPU face the compatibility</span>
        <span class="token comment"># issues with actual armv7 builds.  We should try to install the</span>
        <span class="token comment"># armv5 binary instead.</span>
        <span class="token comment">#</span>
        <span class="token comment"># See https://github.com/AdguardTeam/AdGuardHome/issues/2542.</span>
        <span class="token keyword">if</span> <span class="token punctuation">[</span> <span class="token string">"<span class="token variable">$cpu</span>"</span> <span class="token operator">=</span> <span class="token string">'armv7'</span> <span class="token punctuation">]</span>
        <span class="token keyword">then</span>
                <span class="token assign-left variable">cpu</span><span class="token operator">=</span><span class="token string">'armv5'</span>
                <span class="token assign-left variable">reinstall</span><span class="token operator">=</span><span class="token string">'1'</span>

                log <span class="token string">"trying to use <span class="token variable">$cpu</span> cpu"</span>

                rerun_with_root
        <span class="token keyword">fi</span>

        error_exit <span class="token string">'cannot install AdGuardHome as a service'</span>
<span class="token punctuation">&#125;</span>



<span class="token comment"># Entrypoint</span>

<span class="token comment"># Set default values of configuration variables.</span>
<span class="token assign-left variable">channel</span><span class="token operator">=</span><span class="token string">'release'</span>
<span class="token assign-left variable">reinstall</span><span class="token operator">=</span><span class="token string">'0'</span>
<span class="token assign-left variable">uninstall</span><span class="token operator">=</span><span class="token string">'0'</span>
<span class="token assign-left variable">verbose</span><span class="token operator">=</span><span class="token string">'0'</span>
<span class="token assign-left variable">cpu</span><span class="token operator">=</span><span class="token string">''</span>
<span class="token assign-left variable">os</span><span class="token operator">=</span><span class="token string">''</span>
<span class="token assign-left variable">out_dir</span><span class="token operator">=</span><span class="token string">'/opt'</span>
<span class="token assign-left variable">pkg_ext</span><span class="token operator">=</span><span class="token string">'tar.gz'</span>
<span class="token assign-left variable">download_func</span><span class="token operator">=</span><span class="token string">'download_curl'</span>
<span class="token assign-left variable">sudo_cmd</span><span class="token operator">=</span><span class="token string">'sudo'</span>

parse_opts <span class="token string">"<span class="token variable">$@</span>"</span>

<span class="token builtin class-name">echo</span> <span class="token string">'starting AdGuard Home installation script'</span>

configure
check_required

<span class="token keyword">if</span> <span class="token operator">!</span> is_root
<span class="token keyword">then</span>
        rerun_with_root
<span class="token keyword">fi</span>
<span class="token comment"># Needs rights.</span>
fix_freebsd

handle_existing

download
unpack

install_service

<span class="token builtin class-name">echo</span> <span class="token string">"\
AdGuard Home is now installed and running
you can control the service status with the following commands:
<span class="token variable">$sudo_cmd</span> <span class="token variable">$&#123;agh_dir&#125;</span>/AdGuardHome -s start|stop|restart|status|install|uninstall"</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<h4 id="基本操作"><a href="#基本操作" class="headerlink" title="基本操作"></a>基本操作</h4><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">bash</span> AdGuard-install.sh
<span class="token comment">#############################日志和命令提示，忽略##########################</span>
starting AdGuard Home installation script
<span class="token number">2023</span>/06/08 <span class="token number">20</span>:48:49 <span class="token punctuation">[</span>info<span class="token punctuation">]</span> AdGuard Home, version v0.107.30
<span class="token number">2023</span>/06/08 <span class="token number">20</span>:48:49 <span class="token punctuation">[</span>info<span class="token punctuation">]</span> service: control action: <span class="token function">install</span>
<span class="token number">2023</span>/06/08 <span class="token number">20</span>:48:51 <span class="token punctuation">[</span>info<span class="token punctuation">]</span> service: started
<span class="token number">2023</span>/06/08 <span class="token number">20</span>:48:51 <span class="token punctuation">[</span>info<span class="token punctuation">]</span> Almost ready<span class="token operator">!</span>
AdGuard Home is successfully installed and will automatically start on boot.
There are a few <span class="token function">more</span> things that must be configured before you can use it.
Click on the <span class="token function">link</span> below and follow the Installation Wizard steps to finish setup.
AdGuard Home is now available at the following addresses:
<span class="token number">2023</span>/06/08 <span class="token number">20</span>:48:51 <span class="token punctuation">[</span>info<span class="token punctuation">]</span> go to http://127.0.0.1:3000
<span class="token number">2023</span>/06/08 <span class="token number">20</span>:48:51 <span class="token punctuation">[</span>info<span class="token punctuation">]</span> go to http://<span class="token punctuation">[</span>::1<span class="token punctuation">]</span>:3000
<span class="token number">2023</span>/06/08 <span class="token number">20</span>:48:51 <span class="token punctuation">[</span>info<span class="token punctuation">]</span> go to http://192.168.188.102:3000
<span class="token number">2023</span>/06/08 <span class="token number">20</span>:48:51 <span class="token punctuation">[</span>info<span class="token punctuation">]</span> go to http://<span class="token punctuation">[</span>fe80::a504:c5ad:2b71:be91%eth0<span class="token punctuation">]</span>:3000
<span class="token number">2023</span>/06/08 <span class="token number">20</span>:48:51 <span class="token punctuation">[</span>info<span class="token punctuation">]</span> go to http://172.31.0.1:3000
<span class="token number">2023</span>/06/08 <span class="token number">20</span>:48:51 <span class="token punctuation">[</span>info<span class="token punctuation">]</span> go to http://10.10.10.7:3000
<span class="token number">2023</span>/06/08 <span class="token number">20</span>:48:51 <span class="token punctuation">[</span>info<span class="token punctuation">]</span> service: action <span class="token function">install</span> has been <span class="token keyword">done</span> successfully on linux-systemd
AdGuard Home is now installed and running
you can control the <span class="token function">service</span> status with the following commands:
<span class="token function">sudo</span> /opt/AdGuardHome/AdGuardHome <span class="token parameter variable">-s</span> start<span class="token operator">|</span>stop<span class="token operator">|</span>restart<span class="token operator">|</span>status<span class="token operator">|</span><span class="token function">install</span><span class="token operator">|</span>uninstall
<span class="token comment">#############################################################</span>

<span class="token comment">#占用53端口解决方法</span>
<span class="token function">sudo</span> <span class="token function">mkdir</span> <span class="token parameter variable">-p</span> /etc/systemd/resolved.conf.d
<span class="token function">cat</span> <span class="token operator">></span> /etc/systemd/resolved.conf.d/adguardhome.conf <span class="token operator">&lt;&lt;</span> <span class="token string">EOF
[Resolve]
DNS=127.0.0.1
DNSStubListener=no
EOF</span>

<span class="token function">sudo</span> <span class="token function">mv</span> /etc/resolv.conf /etc/resolv.conf.backup
<span class="token function">sudo</span> <span class="token function">ln</span> <span class="token parameter variable">-s</span> /run/systemd/resolve/resolv.conf /etc/resolv.conf

<span class="token comment">#策略跟下面对应文件修改即可</span>
<span class="token function">vim</span> /opt/AdGuardHome/AdGuardHome.yaml<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>





<h4 id="容器安装"><a href="#容器安装" class="headerlink" title="容器安装"></a>容器安装</h4><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">systemctl stop unbound <span class="token operator">&amp;&amp;</span> systemctl disable unbound

<span class="token comment">#占用53端口解决方法</span>
<span class="token function">sudo</span> <span class="token function">mkdir</span> <span class="token parameter variable">-p</span> /etc/systemd/resolved.conf.d
<span class="token function">cat</span> <span class="token operator">></span> /etc/systemd/resolved.conf.d/adguardhome.conf <span class="token operator">&lt;&lt;</span> <span class="token string">EOF
[Resolve]
DNS=127.0.0.1
DNSStubListener=no
EOF</span>

<span class="token function">sudo</span> <span class="token function">mv</span> /etc/resolv.conf /etc/resolv.conf.backup
<span class="token function">sudo</span> <span class="token function">ln</span> <span class="token parameter variable">-s</span> /run/systemd/resolve/resolv.conf /etc/resolv.conf

<span class="token function">mkdir</span> <span class="token parameter variable">-p</span> /data/adguard-home/<span class="token punctuation">&#123;</span>data,conf<span class="token punctuation">&#125;</span>
<span class="token function">docker</span> run <span class="token parameter variable">--name</span> adguard-home <span class="token parameter variable">--restart</span> unless-stopped <span class="token parameter variable">-v</span> /data/adguard-home/data:/opt/adguardhome/work <span class="token parameter variable">-v</span> /data/adguard-home/config:/opt/adguardhome/conf <span class="token parameter variable">-p</span> <span class="token number">53</span>:53/tcp <span class="token parameter variable">-p</span> <span class="token number">53</span>:53/udp <span class="token parameter variable">-p</span> <span class="token number">67</span>:67/udp <span class="token parameter variable">-p</span> <span class="token number">3000</span>:3000/tcp <span class="token parameter variable">-d</span> adguard/adguardhome

<span class="token comment">#然后配置账号密码</span>
<span class="token function">cp</span> /data/adguard-home/config/AdGuardHome.yaml /data/adguard-home/config/AdGuardHome.yaml.bak

<span class="token assign-left variable">tmp_name_adg</span><span class="token operator">=</span><span class="token variable"><span class="token variable">`</span><span class="token function">cat</span> /data/adguard-home/config/AdGuardHome.yaml.bak <span class="token operator">|</span> <span class="token function">grep</span> name <span class="token operator">|</span> <span class="token function">head</span> -n1<span class="token operator">|</span><span class="token function">cut</span> <span class="token parameter variable">-f2</span> <span class="token parameter variable">-d</span> <span class="token builtin class-name">:</span><span class="token variable">`</span></span>

<span class="token assign-left variable">tmp_password_adg</span><span class="token operator">=</span><span class="token variable"><span class="token variable">`</span><span class="token function">cat</span> /data/adguard-home/config/AdGuardHome.yaml.bak <span class="token operator">|</span> <span class="token function">grep</span> password <span class="token operator">|</span> <span class="token function">cut</span> <span class="token parameter variable">-f2</span> <span class="token parameter variable">-d</span> <span class="token builtin class-name">:</span><span class="token variable">`</span></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<h3 id="配置广告策略和dns防污染"><a href="#配置广告策略和dns防污染" class="headerlink" title="配置广告策略和dns防污染"></a>配置广告策略和dns防污染</h3><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">cat</span> <span class="token operator">></span> /data/adguard-home/config/AdGuardHome.yaml <span class="token operator">&lt;&lt;</span> <span class="token string">EOF
bind_host: 0.0.0.0
bind_port: 3000
users:
###这里为你的账号密码
  - name: "<span class="token variable">$tmp_name_adg</span>"
    password: "<span class="token variable">$tmp_password_adg</span>"
auth_attempts: 5
block_auth_min: 15
http_proxy: ""
language: ""
theme: auto
debug_pprof: false
web_session_ttl: 720
dns:
  bind_hosts:
    - 0.0.0.0
  port: 53
  anonymize_client_ip: false
  protection_enabled: true
  blocking_mode: default
  blocking_ipv4: ""
  blocking_ipv6: ""
  blocked_response_ttl: 10
  protection_disabled_until: null
  parental_block_host: family-block.dns.adguard.com
  safebrowsing_block_host: standard-block.dns.adguard.com
  ratelimit: 20
  ratelimit_whitelist: []
  refuse_any: true
  upstream_dns:
    - 223.5.5.5
    - 114.114.114.114
    - 8.8.8.8
    - https://doh.360.cn/dns-query
    - https://dns.alidns.com/dns-query
  upstream_dns_file: ""
  bootstrap_dns:
  ##这里改为你本地运营上的dns，通过拨号上网可以查询到，没有就填写223.5.5.5和114.114.114.114
    - 202.96.128.166
    - 116.116.116.116
  all_servers: true
  fastest_addr: false
  fastest_timeout: 1s
  allowed_clients: []
  disallowed_clients: []
  blocked_hosts:
    - version.bind
    - id.server
    - hostname.bind
  trusted_proxies:
    - 127.0.0.0/8
    - ::1/128
  cache_size: 4194304
  cache_ttl_min: 0
  cache_ttl_max: 0
  cache_optimistic: false
  bogus_nxdomain: []
  aaaa_disabled: false
  enable_dnssec: false
  edns_client_subnet:
    custom_ip: ""
    enabled: false
    use_custom: false
  max_goroutines: 300
  handle_ddr: true
  ipset: []
  ipset_file: ""
  bootstrap_prefer_ipv6: false
  filtering_enabled: true
  filters_update_interval: 24
  parental_enabled: false
  safebrowsing_enabled: false
  safebrowsing_cache_size: 1048576
  safesearch_cache_size: 1048576
  parental_cache_size: 1048576
  cache_time: 30
  safe_search:
    enabled: false
    bing: true
    duckduckgo: true
    google: true
    pixabay: true
    yandex: true
    youtube: true
  rewrites: []
  blocked_services: []
  upstream_timeout: 10s
  private_networks: []
  use_private_ptr_resolvers: true
  local_ptr_upstreams: []
  use_dns64: false
  dns64_prefixes: []
  serve_http3: false
  use_http3_upstreams: false
tls:
  enabled: false
  server_name: ""
  force_https: false
  port_https: 443
  port_dns_over_tls: 853
  port_dns_over_quic: 853
  port_dnscrypt: 0
  dnscrypt_config_file: ""
  allow_unencrypted_doh: false
  certificate_chain: ""
  private_key: ""
  certificate_path: ""
  private_key_path: ""
  strict_sni_check: false
querylog:
  ignored: []
  interval: 2160h
  size_memory: 1000
  enabled: true
  file_enabled: true
statistics:
  ignored: []
  interval: 24h
  enabled: true
filters:
  - enabled: true
    url: https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt
    name: AdGuard DNS filter
    id: 1228750870
  - enabled: true
    url: http://sub.adtchrome.com/adt-chinalist-easylist.txt
    name: 广告终结者使用的拦截规则，基于ChinaList+EasyList修正维护
    id: 139789181
  - enabled: true
    url: https://easylist-downloads.adblockplus.org/easylist.txt
    name: EasyList-去除国际网页中大多数广告，包括不需要的框架、图像和对象
    id: 139789112
  - enabled: true
    url: https://easylist-downloads.adblockplus.org/easylistchina.txt
    name: EasyList China-EasyList针对国内的补充规则
    id: 139789121
  - enabled: true
    url: https://anti-ad.net/adguard.txt
    name: anti-AD命中率最高列表
    id: 139789122
  - enabled: true
    url: https://raw.iqiq.io/banbendalao/ADgk/master/ADgk.txt
    name: ADgk去广告easylistchina补充规则
    id: 139789131
  - enabled: true
    url: https://raw.iqiq.io/banbendalao/ADgk/master/kill-baidu-ad.txt
    name: ADgk百度广告过滤
    id: 139789133
  - enabled: false
    url: https://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&amp;showintro=1&amp;mimetype=plaintext
    name: Peter Lowe’s Ad and tracking server list​
    id: 139789152
  - enabled: false
    url: https://easylist.to/easylist/fanboy-social.txt
    name: Fanboy's Social Blocking List
    id: 139789153
  - enabled: false
    url: https://easylist.to/easylist/fanboy-annoyance.txt
    name: Fanboy's Annoyance List
    id: 139789154
  - enabled: false
    url: https://secure.fanboy.co.nz/fanboy-cookiemonster.txt
    name: EasyList Cookie List
    id: 139789155
  - enabled: false
    url: https://fanboy.co.nz/fanboy-antifacebook.txt
    name: Anti-Facebook List
    id: 139789161
  - enabled: false
    url: https://filters.adtidy.org/extension/ublock/filters/14.txt
    name: AdGuard Annoyances filter
    id: 139789162
  - enabled: false
    url: https://www.fanboy.co.nz/enhancedstats.txt
    name: Fanboy's Enhanced Tracking List
    id: 139789164
  - enabled: false
    url: https://filters.adtidy.org/extension/ublock/filters/3.txt
    name: AdGuard Tracking Protection filter
    id: 139789165
  - enabled: false
    url: https://easylist.to/easylist/easylist.txt
    name: EasyList
    id: 139789171
  - enabled: false
    url: https://filters.adtidy.org/extension/ublock/filters/11.txt
    name: AdGuard Mobile Ads filter
    id: 139789172
  - enabled: false
    url: https://filters.adtidy.org/extension/ublock/filters/2_without_easylist.txt
    name: AdGuard Base filter
    id: 139789173
  - enabled: false
    url: https://easylist-downloads.adblockplus.org/antiadblockfilters.txt
    name: Adblock Warning Removal List
    id: 139789174
  - enabled: false
    url: https://fanboy.co.nz/fanboy-problematic-sites.txt
    name: Fanboy's problematic-sites
    id: 139789175
  - enabled: false
    url: https://adaway.org/hosts.txt
    name: Adaway HOST
    id: 139789187
whitelist_filters: []
user_rules:
  - '@@||taobao.com^<span class="token variable">$important</span>'
  - '@@||tmall.com^<span class="token variable">$important</span>'
  - '@@||jd.com^important'
  - '@@||flyme.cn^<span class="token variable">$important</span>'
  - '@@||meizu.com^<span class="token variable">$important</span>'
  - '@@||wl.jd.com^<span class="token variable">$important</span>'
  - '@@||flydigi.com^'
  - '@@||pv.sohu.com^<span class="token variable">$important</span>'
  - /googleads.$~script,domain=~googleads.github.io
  - /pagead/lvz?
  - '||google.com/pagead/'
  - '||static.doubleclick.net^<span class="token variable">$domain</span>=youtube.com'
  - '||youtube.com/get_midroll_'
  - '||5hz.org^'
  - '@@||000714.xyz^'
  - '@@||blueskyxn.com^'
  - '||topnewsfeeds.net^'
  - '||nbryb.com^'
  - '||superbdolly.com^'
  - '||salutationcheerlessdemote.com^'
  - '||buildingdoodlesquare.com^'
  - '||colonistnobilityheroic.com^'
dhcp:
  enabled: false
  interface_name: ""
  local_domain_name: lan
  dhcpv4:
    gateway_ip: ""
    subnet_mask: ""
    range_start: ""
    range_end: ""
    lease_duration: 86400
    icmp_timeout_msec: 1000
    options: []
  dhcpv6:
    range_start: ""
    lease_duration: 86400
    ra_slaac_only: false
    ra_allow_slaac: false
clients:
  runtime_sources:
    whois: true
    arp: true
    rdns: true
    dhcp: true
    hosts: true
  persistent: []
log_file: ""
log_max_backups: 0
log_max_size: 100
log_max_age: 3
log_compress: false
log_localtime: false
verbose: false
os:
  group: ""
  user: ""
  rlimit_nofile: 0
schema_version: 20
EOF</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>



<h2 id="测试"><a href="#测试" class="headerlink" title="测试"></a>测试</h2><h3 id="安装samba服务"><a href="#安装samba服务" class="headerlink" title="安装samba服务"></a>安装samba服务</h3><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">apt</span> <span class="token function">install</span> samba samba-common <span class="token parameter variable">-y</span>

<span class="token function">cp</span> /etc/samba/smb.conf /etc/samba/smb.conf.bak

<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span></span></code></pre>

<h4 id="配置samba服务文件"><a href="#配置samba服务文件" class="headerlink" title="配置samba服务文件"></a>配置samba服务文件</h4><p>vim &#x2F;etc&#x2F;samba&#x2F;smb.conf</p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token punctuation">[</span>global<span class="token punctuation">]</span>
        <span class="token function">printcap</span> <span class="token assign-left variable">name</span><span class="token operator">=</span>cups
        winbind enum <span class="token assign-left variable">groups</span><span class="token operator">=</span>yes
        <span class="token comment">#include=/var/tmp/nginx/smb.netbios.aliases.conf</span>
        min <span class="token assign-left variable">protocol</span><span class="token operator">=</span>SMB2
        <span class="token assign-left variable">security</span><span class="token operator">=</span>user
        <span class="token builtin class-name">local</span> <span class="token assign-left variable">master</span><span class="token operator">=</span>no
        <span class="token assign-left variable">realm</span><span class="token operator">=</span>*
        passdb <span class="token assign-left variable">backend</span><span class="token operator">=</span>smbpasswd
        <span class="token assign-left variable">printing</span><span class="token operator">=</span>cups
        max <span class="token assign-left variable">protocol</span><span class="token operator">=</span>SMB3
        winbind enum <span class="token assign-left variable">users</span><span class="token operator">=</span>yes
        load <span class="token assign-left variable">printers</span><span class="token operator">=</span>yes
        <span class="token assign-left variable">workgroup</span><span class="token operator">=</span>WORKGROUP


<span class="token comment">#显示共享名称</span>
<span class="token punctuation">[</span>data<span class="token punctuation">]</span>
        <span class="token comment">#是否ftp可修改</span>
        <span class="token comment">#ftp disable modify=no</span>
        <span class="token comment">#是否关闭ftp下载</span>
        <span class="token comment">#ftp disable download=no</span>
        <span class="token comment">#是否让关闭ftp连接</span>
        <span class="token comment">#ftp disable list=no</span>
        <span class="token comment">#是否在网络邻居可见该目录</span>
        <span class="token assign-left variable">browseable</span><span class="token operator">=</span>yes
        <span class="token comment">#是否允许写入</span>
        <span class="token assign-left variable">writeable</span><span class="token operator">=</span>yes
        <span class="token comment">#是否隐藏不可读</span>
        hide <span class="token assign-left variable">unreadable</span><span class="token operator">=</span>no
        <span class="token comment">#是否让Windows系统共享</span>
        <span class="token comment">#win share=yes</span>
        <span class="token comment">#是否管理员开启回收站</span>
        <span class="token comment">#recycle bin admin only=no</span>
        <span class="token comment">#是否开启回收站</span>
        <span class="token comment">#enable recycle bin=no</span>
        <span class="token comment">#可写入用户</span>
        <span class="token function">write</span> <span class="token assign-left variable">list</span><span class="token operator">=</span>nobody,nobody
        <span class="token comment">#可读取用户</span>
        <span class="token builtin class-name">read</span> <span class="token assign-left variable">list</span><span class="token operator">=</span>nobody,nobody
        <span class="token comment">#无效的用户列表</span>
        invalid <span class="token assign-left variable">users</span><span class="token operator">=</span>nobody,nobody
        <span class="token comment">#有效的用户列表一般用不上</span>
        <span class="token comment">#valid users=nobody,nobody</span>
        <span class="token comment">#来宾用户访问</span>
        guest <span class="token assign-left variable">ok</span><span class="token operator">=</span>yes
        <span class="token comment">#是否同步写入</span>
        <span class="token comment">#edit synoacl=yes</span>
        <span class="token comment">#共享路径注意访问目录用户权限是否拥有</span>
        <span class="token assign-left variable">path</span><span class="token operator">=</span>/data
        <span class="token comment">#是否跳过加密</span>
        <span class="token comment">#skip smb perm=yes</span>
        <span class="token comment">#网上显示备注</span>
        <span class="token assign-left variable">comment</span><span class="token operator">=</span><span class="token string">"视频"</span>
        <span class="token comment">#是否加密一般用不上性能会下降</span>
        <span class="token comment">#encryption=hide</span>
        <span class="token comment">#目录加密key一般用不上性能会下降</span>
        <span class="token comment">#lenEncKey=32</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<h4 id="重启samba服务"><a href="#重启samba服务" class="headerlink" title="重启samba服务"></a>重启samba服务</h4><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">systemctl restart smbd<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>


                
            </div>
            <hr/>

            

    <div class="reprint" id="reprint-statement">
        
            <div class="reprint__author">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-user">
                        文章作者:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="/about" rel="external nofollow noreferrer">Mr.Rootkit</a>
                </span>
            </div>
            <div class="reprint__type">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-link">
                        文章链接:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="https://zerohacker.gitee.io/2023/06/26/%E6%96%90%E8%AE%AFN1%E6%8A%98%E8%85%BE%E6%95%99%E7%A8%8B/">https://zerohacker.gitee.io/2023/06/26/%E6%96%90%E8%AE%AFN1%E6%8A%98%E8%85%BE%E6%95%99%E7%A8%8B/</a>
                </span>
            </div>
            <div class="reprint__notice">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-copyright">
                        版权声明:
                    </i>
                </span>
                <span class="reprint-info">
                    本博客所有文章除特別声明外，均采用
                    <a href="https://creativecommons.org/licenses/by/4.0/deed.zh" rel="external nofollow noreferrer" target="_blank">CC BY 4.0</a>
                    许可协议。转载请注明来源
                    <a href="/about" target="_blank">Mr.Rootkit</a>
                    !
                </span>
            </div>
        
    </div>

    <script async defer>
      document.addEventListener("copy", function (e) {
        let toastHTML = '<span>复制成功，请遵循本文的转载规则</span><button class="btn-flat toast-action" onclick="navToReprintStatement()" style="font-size: smaller">查看</a>';
        M.toast({html: toastHTML})
      });

      function navToReprintStatement() {
        $("html, body").animate({scrollTop: $("#reprint-statement").offset().top - 80}, 800);
      }
    </script>



            <div class="tag_share" style="display: block;">
                <div class="post-meta__tag-list" style="display: inline-block;">
                    
                        <div class="article-tag">
                            
                                <a href="/tags/%E8%BD%AF%E8%B7%AF%E7%94%B1/">
                                    <span class="chip bg-color">软路由</span>
                                </a>
                            
                                <a href="/tags/openwrt/">
                                    <span class="chip bg-color">openwrt</span>
                                </a>
                            
                                <a href="/tags/armbian/">
                                    <span class="chip bg-color">armbian</span>
                                </a>
                            
                                <a href="/tags/%E7%94%B5%E8%A7%86%E7%9B%92%E5%AD%90/">
                                    <span class="chip bg-color">电视盒子</span>
                                </a>
                            
                        </div>
                    
                </div>
                <div class="post_share" style="zoom: 80%; width: fit-content; display: inline-block; float: right; margin: -0.15rem 0;">
                    <link rel="stylesheet" type="text/css" href="/libs/share/css/share.min.css">
<div id="article-share">

    
    <div class="social-share" data-sites="twitter,facebook,google,qq,qzone,wechat,weibo,douban,linkedin" data-wechat-qrcode-helper="<p>微信扫一扫即可分享！</p>"></div>
    <script src="/libs/share/js/social-share.min.js"></script>
    

    

</div>

                </div>
            </div>
            
                <div id="reward">
    <a href="#rewardModal" class="reward-link modal-trigger btn-floating btn-medium waves-effect waves-light red">赏</a>

    <!-- Modal Structure -->
    <div id="rewardModal" class="modal">
        <div class="modal-content">
            <a class="close modal-close"><i class="fas fa-times"></i></a>
            <h4 class="reward-title">你的赏识是我前进的动力</h4>
            <div class="reward-content">
                <div class="reward-tabs">
                    <ul class="tabs row">
                        <li class="tab col s6 alipay-tab waves-effect waves-light"><a href="#alipay">支付宝</a></li>
                        <li class="tab col s6 wechat-tab waves-effect waves-light"><a href="#wechat">微 信</a></li>
                    </ul>
                    <div id="alipay">
                        <img src="/medias/reward/alipay.jpg" class="reward-img" alt="支付宝打赏二维码">
                    </div>
                    <div id="wechat">
                        <img src="/medias/reward/wechat.png" class="reward-img" alt="微信打赏二维码">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('.tabs').tabs();
    });
</script>

            
        </div>
    </div>

    

    

    

    

    

    

    

    

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge left-badge text-color">
                <i class="fas fa-chevron-left"></i>&nbsp;上一篇</div>
            <div class="card">
                <a href="/2023/08/17/Ubuntu22-04-headscale%E9%83%A8%E7%BD%B2/">
                    <div class="card-image">
                        
                        <img src="/images/Ubuntu22-04-headscale%E9%83%A8%E7%BD%B2/top4.jpg" class="responsive-img" alt="Ubuntu22.04-headscale部署">
                        
                        <span class="card-title">Ubuntu22.04-headscale部署</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            Tailscale 是一种基于 WireGuard 的虚拟组网工具，和 Netmaker 类似，最大的区别在于 Tailscale 是在用户态实现了 WireGuard 协议，而 Netmaker 直接使用了内核态的 WireGuard。所以 Tailscale 相比于内核态 WireGuard 性能会有所损失，但与 OpenVPN 之流相比还是能甩好几十条街的，Tailscale 虽然在性能上做了些许取舍，但在功能和易用性上绝对是完爆其他工具.
                        
                    </div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="far fa-clock fa-fw icon-date"></i>2023-08-17
                        </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/VPN%E6%8A%98%E8%85%BE%E5%90%88%E9%9B%86/" class="post-category">
                                    VPN折腾合集
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/VPN/">
                        <span class="chip bg-color">VPN</span>
                    </a>
                    
                    <a href="/tags/wireguard/">
                        <span class="chip bg-color">wireguard</span>
                    </a>
                    
                    <a href="/tags/headscale/">
                        <span class="chip bg-color">headscale</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge right-badge text-color">
                下一篇&nbsp;<i class="fas fa-chevron-right"></i>
            </div>
            <div class="card">
                <a href="/2023/06/13/%E5%BF%AB%E9%80%9F%E9%83%A8%E7%BD%B2%E4%B8%80%E5%A5%97k3s%E9%9B%86%E7%BE%A4/">
                    <div class="card-image">
                        
                        <img src="/images/%E5%BF%AB%E9%80%9F%E9%83%A8%E7%BD%B2%E4%B8%80%E5%A5%97k3s%E9%9B%86%E7%BE%A4/top.jpg" class="responsive-img" alt="快速部署一套k3s集群">
                        
                        <span class="card-title">快速部署一套k3s集群</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            K3s 是一个轻量级的、完全兼容的 Kubernetes 发行版本。非常适合初学者。
                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="far fa-clock fa-fw icon-date"></i>2023-06-13
                            </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/%E4%BA%91%E5%8E%9F%E7%94%9F/" class="post-category">
                                    云原生
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/%E4%BA%91%E8%AE%A1%E7%AE%97/">
                        <span class="chip bg-color">云计算</span>
                    </a>
                    
                    <a href="/tags/%E5%AE%B9%E5%99%A8%E5%8C%96%E6%8A%80%E6%9C%AF/">
                        <span class="chip bg-color">容器化技术</span>
                    </a>
                    
                    <a href="/tags/pass/">
                        <span class="chip bg-color">pass</span>
                    </a>
                    
                    <a href="/tags/k3s/">
                        <span class="chip bg-color">k3s</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
    </div>
</article>

</div>



<!-- 代码块功能依赖 -->
<script type="text/javascript" src="/libs/codeBlock/codeBlockFuction.js"></script>


  <!-- 是否加载使用自带的 prismjs. -->
  <script type="text/javascript" src="/libs/prism/prism.min.js"></script>


<!-- 代码语言 -->

<script type="text/javascript" src="/libs/codeBlock/codeLang.js"></script>


<!-- 代码块复制 -->

<script type="text/javascript" src="/libs/codeBlock/codeCopy.js"></script>


<!-- 代码块收缩 -->

<script type="text/javascript" src="/libs/codeBlock/codeShrink.js"></script>



    </div>
    <div id="toc-aside" class="expanded col l3 hide-on-med-and-down">
        <div class="toc-widget card" style="background-color: white;">
            <div class="toc-title"><i class="far fa-list-alt"></i>&nbsp;&nbsp;目录</div>
            <div id="toc-content"></div>
        </div>
    </div>
</div>

<!-- TOC 悬浮按钮. -->

<div id="floating-toc-btn" class="hide-on-med-and-down">
    <a class="btn-floating btn-large bg-color">
        <i class="fas fa-list-ul"></i>
    </a>
</div>


<script src="/libs/tocbot/tocbot.min.js"></script>
<script>
    $(function () {
        tocbot.init({
            tocSelector: '#toc-content',
            contentSelector: '#articleContent',
            headingsOffset: -($(window).height() * 0.4 - 45),
            collapseDepth: Number('0'),
            headingSelector: 'h2, h3, h4'
        });

        // Set scroll toc fixed.
        let tocHeight = parseInt($(window).height() * 0.4 - 64);
        let $tocWidget = $('.toc-widget');
        $(window).scroll(function () {
            let scroll = $(window).scrollTop();
            /* add post toc fixed. */
            if (scroll > tocHeight) {
                $tocWidget.addClass('toc-fixed');
            } else {
                $tocWidget.removeClass('toc-fixed');
            }
        });

        
        /* 修复文章卡片 div 的宽度. */
        let fixPostCardWidth = function (srcId, targetId) {
            let srcDiv = $('#' + srcId);
            if (srcDiv.length === 0) {
                return;
            }

            let w = srcDiv.width();
            if (w >= 450) {
                w = w + 21;
            } else if (w >= 350 && w < 450) {
                w = w + 18;
            } else if (w >= 300 && w < 350) {
                w = w + 16;
            } else {
                w = w + 14;
            }
            $('#' + targetId).width(w);
        };

        // 切换TOC目录展开收缩的相关操作.
        const expandedClass = 'expanded';
        let $tocAside = $('#toc-aside');
        let $mainContent = $('#main-content');
        $('#floating-toc-btn .btn-floating').click(function () {
            if ($tocAside.hasClass(expandedClass)) {
                $tocAside.removeClass(expandedClass).hide();
                $mainContent.removeClass('l9');
            } else {
                $tocAside.addClass(expandedClass).show();
                $mainContent.addClass('l9');
            }
            fixPostCardWidth('artDetail', 'prenext-posts');
        });
        
    });
</script>

    

</main>




    <footer class="page-footer bg-color">
    
        <link rel="stylesheet" href="/libs/aplayer/APlayer.min.css">
<style>
    .aplayer .aplayer-lrc p {
        
        display: none;
        
        font-size: 12px;
        font-weight: 700;
        line-height: 16px !important;
    }

    .aplayer .aplayer-lrc p.aplayer-lrc-current {
        
        display: none;
        
        font-size: 15px;
        color: #42b983;
    }

    
    .aplayer.aplayer-fixed.aplayer-narrow .aplayer-body {
        left: -66px !important;
    }

    .aplayer.aplayer-fixed.aplayer-narrow .aplayer-body:hover {
        left: 0px !important;
    }

    
</style>
<div class="">
    
    <div class="row">
        <meting-js class="col l8 offset-l2 m10 offset-m1 s12"
                   server="netease"
                   type="playlist"
                   id="503838841"
                   fixed='true'
                   autoplay='false'
                   theme='#42b983'
                   loop='all'
                   order='random'
                   preload='auto'
                   volume='0.7'
                   list-folded='true'
        >
        </meting-js>
    </div>
</div>

<script src="/libs/aplayer/APlayer.min.js"></script>
<script src="/libs/aplayer/Meting.min.js"></script>

    

    <div class="container row center-align"
         style="margin-bottom: 0px !important;">
        <div class="col s12 m8 l8 copy-right">
            Copyright&nbsp;&copy;
            
                <span id="year">2019-2023</span>
            
            <a href="/about" target="_blank">Mr.Rootkit</a>
            |&nbsp;Powered by&nbsp;<a href="https://hexo.io/" target="_blank">Hexo</a>
            |&nbsp;Theme&nbsp;<a href="https://github.com/blinkfox/hexo-theme-matery" target="_blank">Matery</a>
            
            <br>
            
            
            
                
            
            
                <span id="busuanzi_container_site_pv">
                &nbsp;|&nbsp;<i class="far fa-eye"></i>&nbsp;总访问量:&nbsp;
                    <span id="busuanzi_value_site_pv" class="white-color"></span>
            </span>
            
            
                <span id="busuanzi_container_site_uv">
                &nbsp;|&nbsp;<i class="fas fa-users"></i>&nbsp;总访问人数:&nbsp;
                    <span id="busuanzi_value_site_uv" class="white-color"></span>
            </span>
            
            <br>

            <!-- 运行天数提醒. -->
            
            <br>
            
        </div>
        <div class="col s12 m4 l4 social-link social-statis">
    <a href="https://github.com/liangyoufeng" class="tooltipped" target="_blank" data-tooltip="访问我的GitHub" data-position="top" data-delay="50">
        <i class="fab fa-github"></i>
    </a>



    <a href="mailto:254785258@qq.com" class="tooltipped" target="_blank" data-tooltip="邮件联系我" data-position="top" data-delay="50">
        <i class="fas fa-envelope-open"></i>
    </a>







    <a href="tencent://AddContact/?fromId=50&fromSubId=1&subcmd=all&uin=254785258" class="tooltipped" target="_blank" data-tooltip="QQ联系我: 254785258" data-position="top" data-delay="50">
        <i class="fab fa-qq"></i>
    </a>







    <a href="/atom.xml" class="tooltipped" target="_blank" data-tooltip="RSS 订阅" data-position="top" data-delay="50">
        <i class="fas fa-rss"></i>
    </a>

</div>
    </div>
</footer>

<div class="progress-bar"></div>


    <!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title"><i class="fas fa-search"></i>&nbsp;&nbsp;搜索</span>
            <input type="search" id="searchInput" name="s" placeholder="请输入搜索的关键字"
                   class="search-input">
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script type="text/javascript">
$(function () {
    var searchFunc = function (path, search_id, content_id) {
        'use strict';
        $.ajax({
            url: path,
            dataType: "xml",
            success: function (xmlResponse) {
                // get the contents from search data
                var datas = $("entry", xmlResponse).map(function () {
                    return {
                        title: $("title", this).text(),
                        content: $("content", this).text(),
                        url: $("url", this).text()
                    };
                }).get();
                var $input = document.getElementById(search_id);
                var $resultContent = document.getElementById(content_id);
                $input.addEventListener('input', function () {
                    var str = '<ul class=\"search-result-list\">';
                    var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
                    $resultContent.innerHTML = "";
                    if (this.value.trim().length <= 0) {
                        return;
                    }
                    // perform local searching
                    datas.forEach(function (data) {
                        var isMatch = true;
                        var data_title = data.title.trim().toLowerCase();
                        var data_content = data.content.trim().replace(/<[^>]+>/g, "").toLowerCase();
                        var data_url = data.url;
                        data_url = data_url.indexOf('/') === 0 ? data.url : '/' + data_url;
                        var index_title = -1;
                        var index_content = -1;
                        var first_occur = -1;
                        // only match artiles with not empty titles and contents
                        if (data_title !== '' && data_content !== '') {
                            keywords.forEach(function (keyword, i) {
                                index_title = data_title.indexOf(keyword);
                                index_content = data_content.indexOf(keyword);
                                if (index_title < 0 && index_content < 0) {
                                    isMatch = false;
                                } else {
                                    if (index_content < 0) {
                                        index_content = 0;
                                    }
                                    if (i === 0) {
                                        first_occur = index_content;
                                    }
                                }
                            });
                        }
                        // show search results
                        if (isMatch) {
                            str += "<li><a href='" + data_url + "' class='search-result-title'>" + data_title + "</a>";
                            var content = data.content.trim().replace(/<[^>]+>/g, "");
                            if (first_occur >= 0) {
                                // cut out 100 characters
                                var start = first_occur - 20;
                                var end = first_occur + 80;
                                if (start < 0) {
                                    start = 0;
                                }
                                if (start === 0) {
                                    end = 100;
                                }
                                if (end > content.length) {
                                    end = content.length;
                                }
                                var match_content = content.substr(start, end);
                                // highlight all keywords
                                keywords.forEach(function (keyword) {
                                    var regS = new RegExp(keyword, "gi");
                                    match_content = match_content.replace(regS, "<em class=\"search-keyword\">" + keyword + "</em>");
                                });

                                str += "<p class=\"search-result\">" + match_content + "...</p>"
                            }
                            str += "</li>";
                        }
                    });
                    str += "</ul>";
                    $resultContent.innerHTML = str;
                });
            }
        });
    };

    searchFunc('/search.xml', 'searchInput', 'searchResult');
});
</script>

    <!-- 白天和黑夜主题 -->
<div class="stars-con">
    <div id="stars"></div>
    <div id="stars2"></div>
    <div id="stars3"></div>  
</div>

<script>
    function switchNightMode() {
        $('<div class="Cuteen_DarkSky"><div class="Cuteen_DarkPlanet"></div></div>').appendTo($('body')),
        setTimeout(function () {
            $('body').hasClass('DarkMode') 
            ? ($('body').removeClass('DarkMode'), localStorage.setItem('isDark', '0'), $('#sum-moon-icon').removeClass("fa-sun").addClass('fa-moon')) 
            : ($('body').addClass('DarkMode'), localStorage.setItem('isDark', '1'), $('#sum-moon-icon').addClass("fa-sun").removeClass('fa-moon')),
            
            setTimeout(function () {
            $('.Cuteen_DarkSky').fadeOut(1e3, function () {
                $(this).remove()
            })
            }, 2e3)
        })
    }
</script>

    <!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fas fa-arrow-up"></i>
    </a>
</div>


    <script src="/libs/materialize/materialize.min.js"></script>
    <script src="/libs/masonry/masonry.pkgd.min.js"></script>
    <script src="/libs/aos/aos.js"></script>
    <script src="/libs/scrollprogress/scrollProgress.min.js"></script>
    <script src="/libs/lightGallery/js/lightgallery-all.min.js"></script>
    <script src="/js/matery.js"></script>

    

    
    
    

    <!-- 雪花特效 -->
    

    <!-- 鼠标星星特效 -->
    

     
        <script src="https://ssl.captcha.qq.com/TCaptcha.js"></script>
        <script src="/libs/others/TencentCaptcha.js"></script>
        <button id="TencentCaptcha" data-appid="xxxxxxxxxx" data-cbfn="callback" type="button" hidden></button>
    

    <!-- Baidu Analytics -->

    <!-- Baidu Push -->

<script>
    (function () {
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        } else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>

    
    <script src="/libs/others/clicklove.js" async="async"></script>
    
    
    <script async src="/libs/others/busuanzi.pure.mini.js"></script>
    

    

    

    <!--腾讯兔小巢-->
    
    

    

    

    
    <script src="/libs/instantpage/instantpage.js" type="module"></script>
    

</body>

</html>
